fail_adapt_bad_decl.carbon 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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/class/fail_adapt_bad_decl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_adapt_bad_decl.carbon
  10. // --- fail_not_type.carbon
  11. library "[[@TEST_NAME]]";
  12. class Bad {
  13. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `i32` to `type`
  14. // CHECK:STDERR: adapt 100;
  15. // CHECK:STDERR: ^~~~~~~~~~
  16. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:3: note: type `i32` does not implement interface `ImplicitAs`
  17. // CHECK:STDERR: adapt 100;
  18. // CHECK:STDERR: ^~~~~~~~~~
  19. // CHECK:STDERR:
  20. adapt 100;
  21. }
  22. // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:18: error: name `F` not found
  23. // CHECK:STDERR: fn Use(b: Bad) { b.F(); }
  24. // CHECK:STDERR: ^~~
  25. // CHECK:STDERR:
  26. fn Use(b: Bad) { b.F(); }
  27. // --- fail_extend_not_type.carbon
  28. library "[[@TEST_NAME]]";
  29. class Bad {
  30. // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `i32` to `type`
  31. // CHECK:STDERR: extend adapt 100;
  32. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  33. // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+4]]:3: note: type `i32` does not implement interface `ImplicitAs`
  34. // CHECK:STDERR: extend adapt 100;
  35. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  36. // CHECK:STDERR:
  37. extend adapt 100;
  38. }
  39. // No diagnostic here, we don't know what names Bad has.
  40. fn Use(b: Bad) { b.F(); }
  41. // --- fail_repeated.carbon
  42. library "[[@TEST_NAME]]";
  43. class MultipleAdapts {
  44. adapt ();
  45. // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class
  46. // CHECK:STDERR: adapt {};
  47. // CHECK:STDERR: ^~~~~~~~~
  48. // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here
  49. // CHECK:STDERR: adapt ();
  50. // CHECK:STDERR: ^~~~~~~~~
  51. // CHECK:STDERR:
  52. adapt {};
  53. }
  54. class MultipleAdaptsSameType {
  55. adapt ();
  56. // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class
  57. // CHECK:STDERR: adapt ();
  58. // CHECK:STDERR: ^~~~~~~~~
  59. // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here
  60. // CHECK:STDERR: adapt ();
  61. // CHECK:STDERR: ^~~~~~~~~
  62. // CHECK:STDERR:
  63. adapt ();
  64. }
  65. // --- fail_bad_scope.carbon
  66. library "[[@TEST_NAME]]";
  67. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:1: error: `adapt` declaration outside class
  68. // CHECK:STDERR: adapt {};
  69. // CHECK:STDERR: ^~~~~~~~~
  70. // CHECK:STDERR:
  71. adapt {};
  72. interface I {
  73. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:3: error: `adapt` declaration outside class
  74. // CHECK:STDERR: adapt {};
  75. // CHECK:STDERR: ^~~~~~~~~
  76. // CHECK:STDERR:
  77. adapt {};
  78. }
  79. class C {
  80. interface I {
  81. // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+3]]:5: error: `adapt` declaration outside class
  82. // CHECK:STDERR: adapt {};
  83. // CHECK:STDERR: ^~~~~~~~~
  84. adapt {};
  85. }
  86. }
  87. // CHECK:STDOUT: --- fail_not_type.carbon
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: constants {
  90. // CHECK:STDOUT: %Bad: type = class_type @Bad [template]
  91. // CHECK:STDOUT: %.1: i32 = int_literal 100 [template]
  92. // CHECK:STDOUT: %ImplicitAs.type.1: type = generic_interface_type @ImplicitAs [template]
  93. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  94. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type.1 = struct_value () [template]
  95. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
  96. // CHECK:STDOUT: %ImplicitAs.type.2: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  97. // CHECK:STDOUT: %Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2) = bind_symbolic_name Self, 1 [symbolic]
  98. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic]
  99. // CHECK:STDOUT: %Self.2: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic]
  100. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  101. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  102. // CHECK:STDOUT: %.3: type = assoc_entity_type %ImplicitAs.type.2, %Convert.type.1 [symbolic]
  103. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, imports.%import_ref.5 [symbolic]
  104. // CHECK:STDOUT: %ImplicitAs.type.3: type = interface_type @ImplicitAs, @ImplicitAs(type) [template]
  105. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(type) [template]
  106. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  107. // CHECK:STDOUT: %.5: type = assoc_entity_type %ImplicitAs.type.3, %Convert.type.2 [template]
  108. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.5 [template]
  109. // CHECK:STDOUT: %.7: %.3 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  110. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  111. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: imports {
  115. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  116. // CHECK:STDOUT: .ImplicitAs = %import_ref.1
  117. // CHECK:STDOUT: import Core//prelude
  118. // CHECK:STDOUT: import Core//prelude/operators
  119. // CHECK:STDOUT: import Core//prelude/types
  120. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  121. // CHECK:STDOUT: import Core//prelude/operators/as
  122. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  123. // CHECK:STDOUT: import Core//prelude/operators/comparison
  124. // CHECK:STDOUT: import Core//prelude/types/bool
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %import_ref.1: %ImplicitAs.type.1 = import_ref Core//prelude/operators/as, inst+46, loaded [template = constants.%ImplicitAs]
  127. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/as, inst+52, unloaded
  128. // CHECK:STDOUT: %import_ref.3: @ImplicitAs.%.1 (%.3) = import_ref Core//prelude/operators/as, inst+71, loaded [symbolic = @ImplicitAs.%.2 (constants.%.7)]
  129. // CHECK:STDOUT: %import_ref.4 = import_ref Core//prelude/operators/as, inst+64, unloaded
  130. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+64, unloaded
  131. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+64, unloaded
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: file {
  135. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  136. // CHECK:STDOUT: .Core = imports.%Core
  137. // CHECK:STDOUT: .Bad = %Bad.decl
  138. // CHECK:STDOUT: .Use = %Use.decl
  139. // CHECK:STDOUT: }
  140. // CHECK:STDOUT: %Core.import = import Core
  141. // CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
  142. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
  143. // CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
  144. // CHECK:STDOUT: %b.param_patt: %Bad = param_pattern %b.patt, runtime_param0
  145. // CHECK:STDOUT: } {
  146. // CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
  147. // CHECK:STDOUT: %param: %Bad = param runtime_param0
  148. // CHECK:STDOUT: %b: %Bad = bind_name b, %param
  149. // CHECK:STDOUT: }
  150. // CHECK:STDOUT: }
  151. // CHECK:STDOUT:
  152. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  153. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  154. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic = %Dest.patt (constants.%Dest.patt)]
  155. // CHECK:STDOUT:
  156. // CHECK:STDOUT: !definition:
  157. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  158. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  159. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  160. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  161. // CHECK:STDOUT: %.1: type = assoc_entity_type @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.1 (constants.%.3)]
  162. // CHECK:STDOUT: %.2: @ImplicitAs.%.1 (%.3) = assoc_entity element0, imports.%import_ref.5 [symbolic = %.2 (constants.%.4)]
  163. // CHECK:STDOUT:
  164. // CHECK:STDOUT: interface {
  165. // CHECK:STDOUT: !members:
  166. // CHECK:STDOUT: .Self = imports.%import_ref.2
  167. // CHECK:STDOUT: .Convert = imports.%import_ref.3
  168. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  169. // CHECK:STDOUT: }
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT:
  172. // CHECK:STDOUT: class @Bad {
  173. // CHECK:STDOUT: %.loc12_9: i32 = int_literal 100 [template = constants.%.1]
  174. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(type) [template = constants.%ImplicitAs.type.3]
  175. // CHECK:STDOUT: %.loc12_12.1: %.5 = specific_constant imports.%import_ref.3, @ImplicitAs(type) [template = constants.%.6]
  176. // CHECK:STDOUT: %Convert.ref: %.5 = name_ref Convert, %.loc12_12.1 [template = constants.%.6]
  177. // CHECK:STDOUT: %.loc12_12.2: type = converted %.loc12_9, <error> [template = <error>]
  178. // CHECK:STDOUT: adapt_decl <error>
  179. // CHECK:STDOUT: %.loc13: <witness> = complete_type_witness <error> [template = <error>]
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: !members:
  182. // CHECK:STDOUT: .Self = constants.%Bad
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT:
  185. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2)) {
  186. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  187. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  188. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: fn[%self.param_patt: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  191. // CHECK:STDOUT: }
  192. // CHECK:STDOUT:
  193. // CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
  194. // CHECK:STDOUT: !entry:
  195. // CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
  196. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  197. // CHECK:STDOUT: return
  198. // CHECK:STDOUT: }
  199. // CHECK:STDOUT:
  200. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  201. // CHECK:STDOUT: %Dest => constants.%Dest
  202. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  203. // CHECK:STDOUT: }
  204. // CHECK:STDOUT:
  205. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  206. // CHECK:STDOUT: %Dest => constants.%Dest
  207. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  208. // CHECK:STDOUT: }
  209. // CHECK:STDOUT:
  210. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  211. // CHECK:STDOUT: %Dest => constants.%Dest
  212. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  213. // CHECK:STDOUT: }
  214. // CHECK:STDOUT:
  215. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  216. // CHECK:STDOUT: %Dest => constants.%Dest
  217. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.2
  218. // CHECK:STDOUT: %Self => constants.%Self.1
  219. // CHECK:STDOUT: }
  220. // CHECK:STDOUT:
  221. // CHECK:STDOUT: specific @ImplicitAs(type) {
  222. // CHECK:STDOUT: %Dest => type
  223. // CHECK:STDOUT: %Dest.patt => type
  224. // CHECK:STDOUT:
  225. // CHECK:STDOUT: !definition:
  226. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.3
  227. // CHECK:STDOUT: %Self => constants.%Self.2
  228. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  229. // CHECK:STDOUT: %Convert => constants.%Convert.2
  230. // CHECK:STDOUT: %.1 => constants.%.5
  231. // CHECK:STDOUT: %.2 => constants.%.6
  232. // CHECK:STDOUT: }
  233. // CHECK:STDOUT:
  234. // CHECK:STDOUT: --- fail_extend_not_type.carbon
  235. // CHECK:STDOUT:
  236. // CHECK:STDOUT: constants {
  237. // CHECK:STDOUT: %Bad: type = class_type @Bad [template]
  238. // CHECK:STDOUT: %.1: i32 = int_literal 100 [template]
  239. // CHECK:STDOUT: %ImplicitAs.type.1: type = generic_interface_type @ImplicitAs [template]
  240. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  241. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type.1 = struct_value () [template]
  242. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic]
  243. // CHECK:STDOUT: %ImplicitAs.type.2: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  244. // CHECK:STDOUT: %Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2) = bind_symbolic_name Self, 1 [symbolic]
  245. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic]
  246. // CHECK:STDOUT: %Self.2: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic]
  247. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  248. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  249. // CHECK:STDOUT: %.3: type = assoc_entity_type %ImplicitAs.type.2, %Convert.type.1 [symbolic]
  250. // CHECK:STDOUT: %.4: %.3 = assoc_entity element0, imports.%import_ref.5 [symbolic]
  251. // CHECK:STDOUT: %ImplicitAs.type.3: type = interface_type @ImplicitAs, @ImplicitAs(type) [template]
  252. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(type) [template]
  253. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  254. // CHECK:STDOUT: %.5: type = assoc_entity_type %ImplicitAs.type.3, %Convert.type.2 [template]
  255. // CHECK:STDOUT: %.6: %.5 = assoc_entity element0, imports.%import_ref.5 [template]
  256. // CHECK:STDOUT: %.7: %.3 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  257. // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
  258. // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
  259. // CHECK:STDOUT: }
  260. // CHECK:STDOUT:
  261. // CHECK:STDOUT: imports {
  262. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  263. // CHECK:STDOUT: .ImplicitAs = %import_ref.1
  264. // CHECK:STDOUT: import Core//prelude
  265. // CHECK:STDOUT: import Core//prelude/operators
  266. // CHECK:STDOUT: import Core//prelude/types
  267. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  268. // CHECK:STDOUT: import Core//prelude/operators/as
  269. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  270. // CHECK:STDOUT: import Core//prelude/operators/comparison
  271. // CHECK:STDOUT: import Core//prelude/types/bool
  272. // CHECK:STDOUT: }
  273. // CHECK:STDOUT: %import_ref.1: %ImplicitAs.type.1 = import_ref Core//prelude/operators/as, inst+46, loaded [template = constants.%ImplicitAs]
  274. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/as, inst+52, unloaded
  275. // CHECK:STDOUT: %import_ref.3: @ImplicitAs.%.1 (%.3) = import_ref Core//prelude/operators/as, inst+71, loaded [symbolic = @ImplicitAs.%.2 (constants.%.7)]
  276. // CHECK:STDOUT: %import_ref.4 = import_ref Core//prelude/operators/as, inst+64, unloaded
  277. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+64, unloaded
  278. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+64, unloaded
  279. // CHECK:STDOUT: }
  280. // CHECK:STDOUT:
  281. // CHECK:STDOUT: file {
  282. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  283. // CHECK:STDOUT: .Core = imports.%Core
  284. // CHECK:STDOUT: .Bad = %Bad.decl
  285. // CHECK:STDOUT: .Use = %Use.decl
  286. // CHECK:STDOUT: }
  287. // CHECK:STDOUT: %Core.import = import Core
  288. // CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
  289. // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
  290. // CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
  291. // CHECK:STDOUT: %b.param_patt: %Bad = param_pattern %b.patt, runtime_param0
  292. // CHECK:STDOUT: } {
  293. // CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
  294. // CHECK:STDOUT: %param: %Bad = param runtime_param0
  295. // CHECK:STDOUT: %b: %Bad = bind_name b, %param
  296. // CHECK:STDOUT: }
  297. // CHECK:STDOUT: }
  298. // CHECK:STDOUT:
  299. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  300. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  301. // CHECK:STDOUT: %Dest.patt: type = symbolic_binding_pattern Dest, 0 [symbolic = %Dest.patt (constants.%Dest.patt)]
  302. // CHECK:STDOUT:
  303. // CHECK:STDOUT: !definition:
  304. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  305. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  306. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  307. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  308. // CHECK:STDOUT: %.1: type = assoc_entity_type @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.1 (constants.%.3)]
  309. // CHECK:STDOUT: %.2: @ImplicitAs.%.1 (%.3) = assoc_entity element0, imports.%import_ref.5 [symbolic = %.2 (constants.%.4)]
  310. // CHECK:STDOUT:
  311. // CHECK:STDOUT: interface {
  312. // CHECK:STDOUT: !members:
  313. // CHECK:STDOUT: .Self = imports.%import_ref.2
  314. // CHECK:STDOUT: .Convert = imports.%import_ref.3
  315. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  316. // CHECK:STDOUT: }
  317. // CHECK:STDOUT: }
  318. // CHECK:STDOUT:
  319. // CHECK:STDOUT: class @Bad {
  320. // CHECK:STDOUT: %.loc12_16: i32 = int_literal 100 [template = constants.%.1]
  321. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(type) [template = constants.%ImplicitAs.type.3]
  322. // CHECK:STDOUT: %.loc12_19.1: %.5 = specific_constant imports.%import_ref.3, @ImplicitAs(type) [template = constants.%.6]
  323. // CHECK:STDOUT: %Convert.ref: %.5 = name_ref Convert, %.loc12_19.1 [template = constants.%.6]
  324. // CHECK:STDOUT: %.loc12_19.2: type = converted %.loc12_16, <error> [template = <error>]
  325. // CHECK:STDOUT: adapt_decl <error>
  326. // CHECK:STDOUT: %.loc13: <witness> = complete_type_witness <error> [template = <error>]
  327. // CHECK:STDOUT:
  328. // CHECK:STDOUT: !members:
  329. // CHECK:STDOUT: .Self = constants.%Bad
  330. // CHECK:STDOUT: has_error
  331. // CHECK:STDOUT: }
  332. // CHECK:STDOUT:
  333. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%ImplicitAs.type (%ImplicitAs.type.2)) {
  334. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest, 0 [symbolic = %Dest (constants.%Dest)]
  335. // CHECK:STDOUT: %ImplicitAs.type: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %ImplicitAs.type (constants.%ImplicitAs.type.2)]
  336. // CHECK:STDOUT: %Self: %ImplicitAs.type.2 = bind_symbolic_name Self, 1 [symbolic = %Self (constants.%Self.2)]
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: fn[%self.param_patt: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  339. // CHECK:STDOUT: }
  340. // CHECK:STDOUT:
  341. // CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
  342. // CHECK:STDOUT: !entry:
  343. // CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
  344. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  345. // CHECK:STDOUT: return
  346. // CHECK:STDOUT: }
  347. // CHECK:STDOUT:
  348. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  349. // CHECK:STDOUT: %Dest => constants.%Dest
  350. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  351. // CHECK:STDOUT: }
  352. // CHECK:STDOUT:
  353. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  354. // CHECK:STDOUT: %Dest => constants.%Dest
  355. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT:
  358. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  359. // CHECK:STDOUT: %Dest => constants.%Dest
  360. // CHECK:STDOUT: %Dest.patt => constants.%Dest
  361. // CHECK:STDOUT: }
  362. // CHECK:STDOUT:
  363. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  364. // CHECK:STDOUT: %Dest => constants.%Dest
  365. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.2
  366. // CHECK:STDOUT: %Self => constants.%Self.1
  367. // CHECK:STDOUT: }
  368. // CHECK:STDOUT:
  369. // CHECK:STDOUT: specific @ImplicitAs(type) {
  370. // CHECK:STDOUT: %Dest => type
  371. // CHECK:STDOUT: %Dest.patt => type
  372. // CHECK:STDOUT:
  373. // CHECK:STDOUT: !definition:
  374. // CHECK:STDOUT: %ImplicitAs.type => constants.%ImplicitAs.type.3
  375. // CHECK:STDOUT: %Self => constants.%Self.2
  376. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  377. // CHECK:STDOUT: %Convert => constants.%Convert.2
  378. // CHECK:STDOUT: %.1 => constants.%.5
  379. // CHECK:STDOUT: %.2 => constants.%.6
  380. // CHECK:STDOUT: }
  381. // CHECK:STDOUT:
  382. // CHECK:STDOUT: --- fail_repeated.carbon
  383. // CHECK:STDOUT:
  384. // CHECK:STDOUT: constants {
  385. // CHECK:STDOUT: %MultipleAdapts: type = class_type @MultipleAdapts [template]
  386. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  387. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  388. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.1 [template]
  389. // CHECK:STDOUT: %MultipleAdaptsSameType: type = class_type @MultipleAdaptsSameType [template]
  390. // CHECK:STDOUT: }
  391. // CHECK:STDOUT:
  392. // CHECK:STDOUT: imports {
  393. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  394. // CHECK:STDOUT: import Core//prelude
  395. // CHECK:STDOUT: import Core//prelude/operators
  396. // CHECK:STDOUT: import Core//prelude/types
  397. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  398. // CHECK:STDOUT: import Core//prelude/operators/as
  399. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  400. // CHECK:STDOUT: import Core//prelude/operators/comparison
  401. // CHECK:STDOUT: import Core//prelude/types/bool
  402. // CHECK:STDOUT: }
  403. // CHECK:STDOUT: }
  404. // CHECK:STDOUT:
  405. // CHECK:STDOUT: file {
  406. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  407. // CHECK:STDOUT: .Core = imports.%Core
  408. // CHECK:STDOUT: .MultipleAdapts = %MultipleAdapts.decl
  409. // CHECK:STDOUT: .MultipleAdaptsSameType = %MultipleAdaptsSameType.decl
  410. // CHECK:STDOUT: }
  411. // CHECK:STDOUT: %Core.import = import Core
  412. // CHECK:STDOUT: %MultipleAdapts.decl: type = class_decl @MultipleAdapts [template = constants.%MultipleAdapts] {} {}
  413. // CHECK:STDOUT: %MultipleAdaptsSameType.decl: type = class_decl @MultipleAdaptsSameType [template = constants.%MultipleAdaptsSameType] {} {}
  414. // CHECK:STDOUT: }
  415. // CHECK:STDOUT:
  416. // CHECK:STDOUT: class @MultipleAdapts {
  417. // CHECK:STDOUT: %.loc5_10: %.1 = tuple_literal ()
  418. // CHECK:STDOUT: %.loc5_11: type = converted %.loc5_10, constants.%.1 [template = constants.%.1]
  419. // CHECK:STDOUT: adapt_decl %.1
  420. // CHECK:STDOUT: %.loc13: %.2 = struct_literal ()
  421. // CHECK:STDOUT: %.loc14: <witness> = complete_type_witness %.1 [template = constants.%.3]
  422. // CHECK:STDOUT:
  423. // CHECK:STDOUT: !members:
  424. // CHECK:STDOUT: .Self = constants.%MultipleAdapts
  425. // CHECK:STDOUT: }
  426. // CHECK:STDOUT:
  427. // CHECK:STDOUT: class @MultipleAdaptsSameType {
  428. // CHECK:STDOUT: %.loc17_10: %.1 = tuple_literal ()
  429. // CHECK:STDOUT: %.loc17_11: type = converted %.loc17_10, constants.%.1 [template = constants.%.1]
  430. // CHECK:STDOUT: adapt_decl %.1
  431. // CHECK:STDOUT: %.loc25: %.1 = tuple_literal ()
  432. // CHECK:STDOUT: %.loc26: <witness> = complete_type_witness %.1 [template = constants.%.3]
  433. // CHECK:STDOUT:
  434. // CHECK:STDOUT: !members:
  435. // CHECK:STDOUT: .Self = constants.%MultipleAdaptsSameType
  436. // CHECK:STDOUT: }
  437. // CHECK:STDOUT:
  438. // CHECK:STDOUT: --- fail_bad_scope.carbon
  439. // CHECK:STDOUT:
  440. // CHECK:STDOUT: constants {
  441. // CHECK:STDOUT: %.1: type = struct_type {} [template]
  442. // CHECK:STDOUT: %I.type.1: type = interface_type @I.1 [template]
  443. // CHECK:STDOUT: %Self.1: %I.type.1 = bind_symbolic_name Self, 0 [symbolic]
  444. // CHECK:STDOUT: %C: type = class_type @C [template]
  445. // CHECK:STDOUT: %I.type.2: type = interface_type @I.2 [template]
  446. // CHECK:STDOUT: %Self.2: %I.type.2 = bind_symbolic_name Self, 0 [symbolic]
  447. // CHECK:STDOUT: %.2: <witness> = complete_type_witness %.1 [template]
  448. // CHECK:STDOUT: }
  449. // CHECK:STDOUT:
  450. // CHECK:STDOUT: imports {
  451. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  452. // CHECK:STDOUT: import Core//prelude
  453. // CHECK:STDOUT: import Core//prelude/operators
  454. // CHECK:STDOUT: import Core//prelude/types
  455. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  456. // CHECK:STDOUT: import Core//prelude/operators/as
  457. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  458. // CHECK:STDOUT: import Core//prelude/operators/comparison
  459. // CHECK:STDOUT: import Core//prelude/types/bool
  460. // CHECK:STDOUT: }
  461. // CHECK:STDOUT: }
  462. // CHECK:STDOUT:
  463. // CHECK:STDOUT: file {
  464. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  465. // CHECK:STDOUT: .Core = imports.%Core
  466. // CHECK:STDOUT: .I = %I.decl
  467. // CHECK:STDOUT: .C = %C.decl
  468. // CHECK:STDOUT: }
  469. // CHECK:STDOUT: %Core.import = import Core
  470. // CHECK:STDOUT: %.loc8: %.1 = struct_literal ()
  471. // CHECK:STDOUT: %I.decl: type = interface_decl @I.1 [template = constants.%I.type.1] {} {}
  472. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  473. // CHECK:STDOUT: }
  474. // CHECK:STDOUT:
  475. // CHECK:STDOUT: interface @I.1 {
  476. // CHECK:STDOUT: %Self: %I.type.1 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.1]
  477. // CHECK:STDOUT: %.loc15: %.1 = struct_literal ()
  478. // CHECK:STDOUT:
  479. // CHECK:STDOUT: !members:
  480. // CHECK:STDOUT: .Self = %Self
  481. // CHECK:STDOUT: witness = ()
  482. // CHECK:STDOUT: }
  483. // CHECK:STDOUT:
  484. // CHECK:STDOUT: interface @I.2 {
  485. // CHECK:STDOUT: %Self: %I.type.2 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.2]
  486. // CHECK:STDOUT: %.loc23: %.1 = struct_literal ()
  487. // CHECK:STDOUT:
  488. // CHECK:STDOUT: !members:
  489. // CHECK:STDOUT: .Self = %Self
  490. // CHECK:STDOUT: witness = ()
  491. // CHECK:STDOUT: }
  492. // CHECK:STDOUT:
  493. // CHECK:STDOUT: class @C {
  494. // CHECK:STDOUT: %I.decl: type = interface_decl @I.2 [template = constants.%I.type.2] {} {}
  495. // CHECK:STDOUT: %.loc25: <witness> = complete_type_witness %.1 [template = constants.%.2]
  496. // CHECK:STDOUT:
  497. // CHECK:STDOUT: !members:
  498. // CHECK:STDOUT: .Self = constants.%C
  499. // CHECK:STDOUT: .I = %I.decl
  500. // CHECK:STDOUT: }
  501. // CHECK:STDOUT: