fail_storage_is_literal.carbon 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/var/fail_storage_is_literal.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/var/fail_storage_is_literal.carbon
  14. fn Main() {
  15. // CHECK:STDERR: fail_storage_is_literal.carbon:[[@LINE+7]]:10: error: cannot implicitly convert non-type value of type `Core.IntLiteral` to `type` [ConversionFailureNonTypeToFacet]
  16. // CHECK:STDERR: var x: 1 = 1;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR: fail_storage_is_literal.carbon:[[@LINE+4]]:10: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  19. // CHECK:STDERR: var x: 1 = 1;
  20. // CHECK:STDERR: ^
  21. // CHECK:STDERR:
  22. var x: 1 = 1;
  23. }
  24. // CHECK:STDOUT: --- fail_storage_is_literal.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  28. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  29. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  30. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  31. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  32. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  37. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  38. // CHECK:STDOUT: .Destroy = %Core.Destroy
  39. // CHECK:STDOUT: import Core//prelude
  40. // CHECK:STDOUT: import Core//prelude/...
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  43. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  48. // CHECK:STDOUT: .Core = imports.%Core
  49. // CHECK:STDOUT: .Main = %Main.decl
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core.import = import Core
  52. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @Main() {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: name_binding_decl {
  58. // CHECK:STDOUT: %x.patt: <error> = ref_binding_pattern x [concrete]
  59. // CHECK:STDOUT: %x.var_patt: <error> = var_pattern %x.patt [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %x.var: ref <error> = var %x.var_patt [concrete = <error>]
  62. // CHECK:STDOUT: %int_1.loc23_14: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  63. // CHECK:STDOUT: assign %x.var, <error>
  64. // CHECK:STDOUT: %.1: <error> = splice_block <error> [concrete = <error>] {
  65. // CHECK:STDOUT: %int_1.loc23_10: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  66. // CHECK:STDOUT: %.loc23: type = converted %int_1.loc23_10, <error> [concrete = <error>]
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %x: ref <error> = ref_binding x, <error> [concrete = <error>]
  69. // CHECK:STDOUT: return
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: