fail_generic_import.carbon 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/let/fail_generic_import.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_generic_import.carbon
  10. // --- implicit.carbon
  11. package Implicit;
  12. let T:! type = i32;
  13. // --- fail_implicit.impl.carbon
  14. impl package Implicit;
  15. // TODO: Should this be valid?
  16. // CHECK:STDERR: fail_implicit.impl.carbon:[[@LINE+6]]:1: error: cannot implicitly convert from `i32` to `T`
  17. // CHECK:STDERR: let a: T = 0;
  18. // CHECK:STDERR: ^~~~~~~~~~~~~
  19. // CHECK:STDERR: fail_implicit.impl.carbon:[[@LINE+3]]:1: note: type `i32` does not implement interface `ImplicitAs`
  20. // CHECK:STDERR: let a: T = 0;
  21. // CHECK:STDERR: ^~~~~~~~~~~~~
  22. let a: T = 0;
  23. // CHECK:STDOUT: --- implicit.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  27. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  28. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  29. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  34. // CHECK:STDOUT: .Int32 = %import_ref
  35. // CHECK:STDOUT: import Core//prelude
  36. // CHECK:STDOUT: import Core//prelude/operators
  37. // CHECK:STDOUT: import Core//prelude/types
  38. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  39. // CHECK:STDOUT: import Core//prelude/operators/as
  40. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  41. // CHECK:STDOUT: import Core//prelude/operators/comparison
  42. // CHECK:STDOUT: import Core//prelude/types/bool
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: file {
  48. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  49. // CHECK:STDOUT: .Core = imports.%Core
  50. // CHECK:STDOUT: .T = @__global_init.%T
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Core.import = import Core
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: fn @__global_init() {
  58. // CHECK:STDOUT: !entry:
  59. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  60. // CHECK:STDOUT: %.loc4_19.1: type = value_of_initializer %int.make_type_32 [template = i32]
  61. // CHECK:STDOUT: %.loc4_19.2: type = converted %int.make_type_32, %.loc4_19.1 [template = i32]
  62. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0, %.loc4_19.2 [symbolic = constants.%T]
  63. // CHECK:STDOUT: return
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: --- fail_implicit.impl.carbon
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: constants {
  69. // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
  70. // CHECK:STDOUT: %.1: i32 = int_literal 0 [template]
  71. // CHECK:STDOUT: %ImplicitAs.type: type = generic_interface_type @ImplicitAs [template]
  72. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  73. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type = struct_value () [template]
  74. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic]
  75. // CHECK:STDOUT: %.3: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  76. // CHECK:STDOUT: %Self.1: @ImplicitAs.%.1 (%.3) = bind_symbolic_name Self 1 [symbolic]
  77. // CHECK:STDOUT: %Self.2: %.3 = bind_symbolic_name Self 1 [symbolic]
  78. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  79. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  80. // CHECK:STDOUT: %.4: type = assoc_entity_type %.3, %Convert.type.1 [symbolic]
  81. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  82. // CHECK:STDOUT: %.6: type = interface_type @ImplicitAs, @ImplicitAs(%T) [symbolic]
  83. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(%T) [symbolic]
  84. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [symbolic]
  85. // CHECK:STDOUT: %.7: type = assoc_entity_type %.6, %Convert.type.2 [symbolic]
  86. // CHECK:STDOUT: %.8: %.7 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  87. // CHECK:STDOUT: %.9: %.4 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: imports {
  91. // CHECK:STDOUT: %import_ref.1: type = import_ref Implicit//default, inst+3, loaded [symbolic = constants.%T]
  92. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  93. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  94. // CHECK:STDOUT: import Core//prelude
  95. // CHECK:STDOUT: import Core//prelude/operators
  96. // CHECK:STDOUT: import Core//prelude/types
  97. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  98. // CHECK:STDOUT: import Core//prelude/operators/as
  99. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  100. // CHECK:STDOUT: import Core//prelude/operators/comparison
  101. // CHECK:STDOUT: import Core//prelude/types/bool
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %import_ref.2: %ImplicitAs.type = import_ref Core//prelude/operators/as, inst+37, loaded [template = constants.%ImplicitAs]
  104. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/as, inst+42, unloaded
  105. // CHECK:STDOUT: %import_ref.4: @ImplicitAs.%.2 (%.4) = import_ref Core//prelude/operators/as, inst+59, loaded [symbolic = @ImplicitAs.%.3 (constants.%.9)]
  106. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+52, unloaded
  107. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+52, unloaded
  108. // CHECK:STDOUT: %import_ref.7 = import_ref Core//prelude/operators/as, inst+52, unloaded
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: file {
  112. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  113. // CHECK:STDOUT: .T = imports.%import_ref.1
  114. // CHECK:STDOUT: .Core = imports.%Core
  115. // CHECK:STDOUT: .a = @__global_init.%a
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: %Implicit.import = import Implicit
  118. // CHECK:STDOUT: %default.import = import <invalid>
  119. // CHECK:STDOUT: %Core.import = import Core
  120. // CHECK:STDOUT: %T.ref: type = name_ref T, imports.%import_ref.1 [symbolic = constants.%T]
  121. // CHECK:STDOUT: }
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  124. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  125. // CHECK:STDOUT:
  126. // CHECK:STDOUT: !definition:
  127. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.3)]
  128. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  129. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  130. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  131. // CHECK:STDOUT: %.2: type = assoc_entity_type @ImplicitAs.%.1 (%.3), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.2 (constants.%.4)]
  132. // CHECK:STDOUT: %.3: @ImplicitAs.%.2 (%.4) = assoc_entity element0, imports.%import_ref.6 [symbolic = %.3 (constants.%.5)]
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: interface {
  135. // CHECK:STDOUT: !members:
  136. // CHECK:STDOUT: .Self = imports.%import_ref.3
  137. // CHECK:STDOUT: .Convert = imports.%import_ref.4
  138. // CHECK:STDOUT: witness = (imports.%import_ref.5)
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%.1 (%.3)) {
  143. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  144. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.3)]
  145. // CHECK:STDOUT: %Self: %.3 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: fn[%self: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: fn @__global_init() {
  151. // CHECK:STDOUT: !entry:
  152. // CHECK:STDOUT: %.loc11_12: i32 = int_literal 0 [template = constants.%.1]
  153. // CHECK:STDOUT: %.loc11_13.1: type = interface_type @ImplicitAs, @ImplicitAs(constants.%T) [symbolic = constants.%.6]
  154. // CHECK:STDOUT: %.loc11_13.2: %.7 = specific_constant imports.%import_ref.4, @ImplicitAs(constants.%T) [symbolic = constants.%.8]
  155. // CHECK:STDOUT: %Convert.ref: %.7 = name_ref Convert, %.loc11_13.2 [symbolic = constants.%.8]
  156. // CHECK:STDOUT: %.loc11_13.3: %T = converted %.loc11_12, <error> [template = <error>]
  157. // CHECK:STDOUT: %a: %T = bind_name a, <error>
  158. // CHECK:STDOUT: return
  159. // CHECK:STDOUT: }
  160. // CHECK:STDOUT:
  161. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  162. // CHECK:STDOUT: %Dest => constants.%Dest
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  166. // CHECK:STDOUT: %Dest => constants.%Dest
  167. // CHECK:STDOUT: }
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  170. // CHECK:STDOUT: %Dest => constants.%Dest
  171. // CHECK:STDOUT: }
  172. // CHECK:STDOUT:
  173. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  174. // CHECK:STDOUT: %Dest => constants.%Dest
  175. // CHECK:STDOUT: %.1 => constants.%.3
  176. // CHECK:STDOUT: %Self => constants.%Self.1
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: specific @ImplicitAs(constants.%T) {
  180. // CHECK:STDOUT: %Dest => constants.%T
  181. // CHECK:STDOUT:
  182. // CHECK:STDOUT: !definition:
  183. // CHECK:STDOUT: %.1 => constants.%.6
  184. // CHECK:STDOUT: %Self => constants.%Self.2
  185. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  186. // CHECK:STDOUT: %Convert => constants.%Convert.2
  187. // CHECK:STDOUT: %.2 => constants.%.7
  188. // CHECK:STDOUT: %.3 => constants.%.8
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT: