fail_generic.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/let/fail_generic.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_generic.carbon
  14. // TODO: Should this be valid?
  15. fn F(a: i32) -> i32 {
  16. let T:! type = i32;
  17. // CHECK:STDERR: fail_generic.carbon:[[@LINE+7]]:14: error: cannot implicitly convert expression of type `Core.IntLiteral` to `T` [ConversionFailure]
  18. // CHECK:STDERR: let x: T = 5;
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR: fail_generic.carbon:[[@LINE+4]]:14: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(T)` [MissingImplInMemberAccessNote]
  21. // CHECK:STDERR: let x: T = 5;
  22. // CHECK:STDERR: ^
  23. // CHECK:STDERR:
  24. let x: T = 5;
  25. // CHECK:STDERR: fail_generic.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `T` to `i32` [ConversionFailure]
  26. // CHECK:STDERR: return x;
  27. // CHECK:STDERR: ^~~~~~~~~
  28. // CHECK:STDERR: fail_generic.carbon:[[@LINE+4]]:3: note: type `T` does not implement interface `Core.ImplicitAs(i32)` [MissingImplInMemberAccessNote]
  29. // CHECK:STDERR: return x;
  30. // CHECK:STDERR: ^~~~~~~~~
  31. // CHECK:STDERR:
  32. return x;
  33. }
  34. // CHECK:STDOUT: --- fail_generic.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  38. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  39. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  40. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  41. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  42. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  43. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  44. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
  45. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  46. // CHECK:STDOUT: %pattern_type.7dcd0a.1: type = pattern_type %T [symbolic]
  47. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete]
  48. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  49. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  50. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
  51. // CHECK:STDOUT: %Convert.type.2751f3.1: type = fn_type @Convert.1, @ImplicitAs(%Dest) [symbolic]
  52. // CHECK:STDOUT: %Convert.42ebb8.1: %Convert.type.2751f3.1 = struct_value () [symbolic]
  53. // CHECK:STDOUT: %ImplicitAs.assoc_type.ca0d85.1: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  54. // CHECK:STDOUT: %ImplicitAs.type.d628ce.2: type = facet_type <@ImplicitAs, @ImplicitAs(%T)> [symbolic]
  55. // CHECK:STDOUT: %ImplicitAs.assoc_type.ca0d85.2: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%T) [symbolic]
  56. // CHECK:STDOUT: %assoc0.9f5e6b.2: %ImplicitAs.assoc_type.ca0d85.2 = assoc_entity element0, imports.%Core.import_ref.1c7 [symbolic]
  57. // CHECK:STDOUT: %assoc0.dc0: %ImplicitAs.assoc_type.ca0d85.1 = assoc_entity element0, imports.%Core.import_ref.207 [symbolic]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: imports {
  61. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  62. // CHECK:STDOUT: .Int = %Core.Int
  63. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  64. // CHECK:STDOUT: import Core//prelude
  65. // CHECK:STDOUT: import Core//prelude/...
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  68. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  69. // CHECK:STDOUT: %Core.import_ref.492: @ImplicitAs.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.ca0d85.1) = import_ref Core//prelude/parts/as, loc12_35, loaded [symbolic = @ImplicitAs.%assoc0 (constants.%assoc0.dc0)]
  70. // CHECK:STDOUT: %Core.import_ref.1c7: @ImplicitAs.%Convert.type (%Convert.type.2751f3.1) = import_ref Core//prelude/parts/as, loc12_35, loaded [symbolic = @ImplicitAs.%Convert (constants.%Convert.42ebb8.1)]
  71. // CHECK:STDOUT: %Core.import_ref.207 = import_ref Core//prelude/parts/as, loc12_35, unloaded
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: file {
  75. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  76. // CHECK:STDOUT: .Core = imports.%Core
  77. // CHECK:STDOUT: .F = %F.decl
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: %Core.import = import Core
  80. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  81. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = binding_pattern a [concrete]
  82. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  83. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  84. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  85. // CHECK:STDOUT: } {
  86. // CHECK:STDOUT: %int_32.loc16_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  87. // CHECK:STDOUT: %i32.loc16_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  88. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  89. // CHECK:STDOUT: %.loc16: type = splice_block %i32.loc16_9 [concrete = constants.%i32] {
  90. // CHECK:STDOUT: %int_32.loc16_9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  91. // CHECK:STDOUT: %i32.loc16_9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %a: %i32 = bind_name a, %a.param
  94. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  95. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @F(%a.param: %i32) -> %i32 {
  100. // CHECK:STDOUT: !entry:
  101. // CHECK:STDOUT: name_binding_decl {
  102. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: %int_32.loc17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  105. // CHECK:STDOUT: %i32.loc17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  106. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, %i32.loc17 [symbolic = constants.%T]
  107. // CHECK:STDOUT: name_binding_decl {
  108. // CHECK:STDOUT: %x.patt: %pattern_type.7dcd0a.1 = binding_pattern x [concrete]
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete = constants.%int_5]
  111. // CHECK:STDOUT: %T.ref: type = name_ref T, %T [symbolic = constants.%T]
  112. // CHECK:STDOUT: %ImplicitAs.type: type = facet_type <@ImplicitAs, @ImplicitAs(constants.%T)> [symbolic = constants.%ImplicitAs.type.d628ce.2]
  113. // CHECK:STDOUT: %.loc25_14.1: %ImplicitAs.assoc_type.ca0d85.2 = specific_constant imports.%Core.import_ref.492, @ImplicitAs(constants.%T) [symbolic = constants.%assoc0.9f5e6b.2]
  114. // CHECK:STDOUT: %Convert.ref: %ImplicitAs.assoc_type.ca0d85.2 = name_ref Convert, %.loc25_14.1 [symbolic = constants.%assoc0.9f5e6b.2]
  115. // CHECK:STDOUT: %.loc25_14.2: %T = converted %int_5, <error> [concrete = <error>]
  116. // CHECK:STDOUT: %x: %T = bind_name x, <error> [concrete = <error>]
  117. // CHECK:STDOUT: %x.ref: %T = name_ref x, %x [concrete = <error>]
  118. // CHECK:STDOUT: %.loc33: %i32 = converted %x.ref, <error> [concrete = <error>]
  119. // CHECK:STDOUT: return <error>
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: