member_access.carbon 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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/generic/template/member_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/template/member_access.carbon
  10. // --- member_access.carbon
  11. library "[[@TEST_NAME]]";
  12. fn F[template T:! type](x: T) -> i32 {
  13. return x.n;
  14. }
  15. class C {
  16. var n: i32;
  17. }
  18. fn Test1(c: C) {
  19. F(c);
  20. }
  21. fn Test2(x: {.m: i32, .n: i32}) {
  22. F(x);
  23. }
  24. // --- fail_no_such_member.carbon
  25. library "[[@TEST_NAME]]";
  26. fn F[template T:! type](x: T) -> i32 {
  27. // CHECK:STDERR: fail_no_such_member.carbon:[[@LINE+3]]:10: error: member name `n` not found in `D` [MemberNameNotFoundInInstScope]
  28. // CHECK:STDERR: return x.n;
  29. // CHECK:STDERR: ^~~
  30. return x.n;
  31. }
  32. class D {
  33. var m: i32;
  34. }
  35. fn Test(d: D) {
  36. // CHECK:STDERR: fail_no_such_member.carbon:[[@LINE+4]]:3: note: in `F(D)` used here [ResolvingSpecificHere]
  37. // CHECK:STDERR: F(d);
  38. // CHECK:STDERR: ^
  39. // CHECK:STDERR:
  40. F(d);
  41. }
  42. // --- fail_member_wrong_type.carbon
  43. library "[[@TEST_NAME]]";
  44. fn F[template T:! type](x: T) -> i32 {
  45. // CHECK:STDERR: fail_member_wrong_type.carbon:[[@LINE+6]]:3: error: cannot implicitly convert expression of type `F` to `i32` [ConversionFailure]
  46. // CHECK:STDERR: return x.n;
  47. // CHECK:STDERR: ^~~~~~~~~~~
  48. // CHECK:STDERR: fail_member_wrong_type.carbon:[[@LINE+3]]:3: note: type `F` does not implement interface `Core.ImplicitAs(i32)` [MissingImplInMemberAccessNote]
  49. // CHECK:STDERR: return x.n;
  50. // CHECK:STDERR: ^~~~~~~~~~~
  51. return x.n;
  52. }
  53. class E {
  54. class F {}
  55. var n: F;
  56. }
  57. fn Test(e: E) {
  58. // CHECK:STDERR: fail_member_wrong_type.carbon:[[@LINE+4]]:3: note: in `F(E)` used here [ResolvingSpecificHere]
  59. // CHECK:STDERR: F(e);
  60. // CHECK:STDERR: ^
  61. // CHECK:STDERR:
  62. F(e);
  63. }
  64. // CHECK:STDOUT: --- member_access.carbon
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: constants {
  67. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, template [template]
  68. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0, template [template]
  69. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  70. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  71. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  72. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  73. // CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [template]
  74. // CHECK:STDOUT: %C: type = class_type @C [concrete]
  75. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %i32 [concrete]
  76. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete]
  77. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [concrete]
  78. // CHECK:STDOUT: %Test1.type: type = fn_type @Test1 [concrete]
  79. // CHECK:STDOUT: %Test1: %Test1.type = struct_value () [concrete]
  80. // CHECK:STDOUT: %F.specific_fn.04a: <specific function> = specific_function %F, @F(%C) [concrete]
  81. // CHECK:STDOUT: %struct_type.m.n: type = struct_type {.m: %i32, .n: %i32} [concrete]
  82. // CHECK:STDOUT: %Test2.type: type = fn_type @Test2 [concrete]
  83. // CHECK:STDOUT: %Test2: %Test2.type = struct_value () [concrete]
  84. // CHECK:STDOUT: %F.specific_fn.92d: <specific function> = specific_function %F, @F(%struct_type.m.n) [concrete]
  85. // CHECK:STDOUT: %inst.as_compatible.c0a: <instruction> = inst_value [concrete] {
  86. // CHECK:STDOUT: %.fbe: %C = as_compatible @F.%x.ref
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %inst.splice_block.d20: <instruction> = inst_value [concrete] {
  89. // CHECK:STDOUT: %.39c: %i32 = splice_block %.e83 {
  90. // CHECK:STDOUT: %n.ref: %C.elem = name_ref n, @C.%.loc9_8 [concrete = @C.%.loc9_8]
  91. // CHECK:STDOUT: %.d20: ref %i32 = class_element_access %.fbe, element0
  92. // CHECK:STDOUT: %.e83: %i32 = bind_value %.d20
  93. // CHECK:STDOUT: }
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %inst.splice_block.435: <instruction> = inst_value [concrete] {
  96. // CHECK:STDOUT: %.460: %i32 = splice_block %.39c {}
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %complete_type.622: <witness> = complete_type_witness %struct_type.m.n [concrete]
  99. // CHECK:STDOUT: %inst.as_compatible.8f8: <instruction> = inst_value [concrete] {
  100. // CHECK:STDOUT: %.61c: %struct_type.m.n = as_compatible @F.%x.ref
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT: %inst.struct_access: <instruction> = inst_value [concrete] {
  103. // CHECK:STDOUT: %.fd5: %i32 = struct_access %.61c, element1
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT: %inst.splice_block.57b: <instruction> = inst_value [concrete] {
  106. // CHECK:STDOUT: %.fbf: %i32 = splice_block %.fd5 {}
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: imports {
  111. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  112. // CHECK:STDOUT: .Int = %Core.Int
  113. // CHECK:STDOUT: import Core//prelude
  114. // CHECK:STDOUT: import Core//prelude/...
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: file {
  119. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  120. // CHECK:STDOUT: .Core = imports.%Core
  121. // CHECK:STDOUT: .F = %F.decl
  122. // CHECK:STDOUT: .C = %C.decl
  123. // CHECK:STDOUT: .Test1 = %Test1.decl
  124. // CHECK:STDOUT: .Test2 = %Test2.decl
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: %Core.import = import Core
  127. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  128. // CHECK:STDOUT: %T.patt.loc4_15.1: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  129. // CHECK:STDOUT: %x.patt: @F.%T.loc4_15.2 (%T) = binding_pattern x
  130. // CHECK:STDOUT: %x.param_patt: @F.%T.loc4_15.2 (%T) = value_param_pattern %x.patt, call_param0
  131. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  132. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param1
  133. // CHECK:STDOUT: } {
  134. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  135. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  136. // CHECK:STDOUT: %T.loc4_15.1: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  137. // CHECK:STDOUT: %x.param: @F.%T.loc4_15.2 (%T) = value_param call_param0
  138. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc4_15.1 [template = %T.loc4_15.2 (constants.%T)]
  139. // CHECK:STDOUT: %x: @F.%T.loc4_15.2 (%T) = bind_name x, %x.param
  140. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  141. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
  144. // CHECK:STDOUT: %Test1.decl: %Test1.type = fn_decl @Test1 [concrete = constants.%Test1] {
  145. // CHECK:STDOUT: %c.patt: %C = binding_pattern c
  146. // CHECK:STDOUT: %c.param_patt: %C = value_param_pattern %c.patt, call_param0
  147. // CHECK:STDOUT: } {
  148. // CHECK:STDOUT: %c.param: %C = value_param call_param0
  149. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
  150. // CHECK:STDOUT: %c: %C = bind_name c, %c.param
  151. // CHECK:STDOUT: }
  152. // CHECK:STDOUT: %Test2.decl: %Test2.type = fn_decl @Test2 [concrete = constants.%Test2] {
  153. // CHECK:STDOUT: %x.patt: %struct_type.m.n = binding_pattern x
  154. // CHECK:STDOUT: %x.param_patt: %struct_type.m.n = value_param_pattern %x.patt, call_param0
  155. // CHECK:STDOUT: } {
  156. // CHECK:STDOUT: %x.param: %struct_type.m.n = value_param call_param0
  157. // CHECK:STDOUT: %.loc16: type = splice_block %struct_type.m.n [concrete = constants.%struct_type.m.n] {
  158. // CHECK:STDOUT: %int_32.loc16_18: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  159. // CHECK:STDOUT: %i32.loc16_18: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  160. // CHECK:STDOUT: %int_32.loc16_27: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  161. // CHECK:STDOUT: %i32.loc16_27: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  162. // CHECK:STDOUT: %struct_type.m.n: type = struct_type {.m: %i32, .n: %i32} [concrete = constants.%struct_type.m.n]
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT: %x: %struct_type.m.n = bind_name x, %x.param
  165. // CHECK:STDOUT: }
  166. // CHECK:STDOUT: }
  167. // CHECK:STDOUT:
  168. // CHECK:STDOUT: class @C {
  169. // CHECK:STDOUT: %.loc9_8: %C.elem = field_decl n, element0 [concrete]
  170. // CHECK:STDOUT: name_binding_decl {
  171. // CHECK:STDOUT: %.loc9_3: %C.elem = var_pattern %.loc9_8
  172. // CHECK:STDOUT: }
  173. // CHECK:STDOUT: %.var: ref %C.elem = var <none>
  174. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete = constants.%struct_type.n]
  175. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.54b]
  176. // CHECK:STDOUT: complete_type_witness = %complete_type
  177. // CHECK:STDOUT:
  178. // CHECK:STDOUT: !members:
  179. // CHECK:STDOUT: .Self = constants.%C
  180. // CHECK:STDOUT: .n = %.loc9_8
  181. // CHECK:STDOUT: }
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: generic fn @F(%T.loc4_15.1: type) {
  184. // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  185. // CHECK:STDOUT: %T.patt.loc4_15.2: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  186. // CHECK:STDOUT:
  187. // CHECK:STDOUT: !definition:
  188. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T.loc4_15.2 [template = %require_complete (constants.%require_complete.4ae)]
  189. // CHECK:STDOUT: %.loc5_11.3: <instruction> = refine_type_action %x.ref, %T.loc4_15.2 [template]
  190. // CHECK:STDOUT: %.loc5_11.4: <instruction> = access_member_action %.loc5_11.1, n [template]
  191. // CHECK:STDOUT: %.loc5_11.5: type = type_of_inst %.loc5_11.4 [template]
  192. // CHECK:STDOUT: %.loc5_13.2: <instruction> = convert_to_value_action %.loc5_11.2, constants.%i32 [template]
  193. // CHECK:STDOUT:
  194. // CHECK:STDOUT: fn[%T.patt.loc4_15.1: type](%x.param_patt: @F.%T.loc4_15.2 (%T)) -> %i32 {
  195. // CHECK:STDOUT: !entry:
  196. // CHECK:STDOUT: %x.ref: @F.%T.loc4_15.2 (%T) = name_ref x, %x
  197. // CHECK:STDOUT: %.loc5_11.1: @F.%T.loc4_15.2 (%T) = splice_inst %.loc5_11.3
  198. // CHECK:STDOUT: %.loc5_11.2: @F.%.loc5_11.5 (@F.%.loc5_11.5) = splice_inst %.loc5_11.4
  199. // CHECK:STDOUT: %.loc5_13.1: %i32 = splice_inst %.loc5_13.2
  200. // CHECK:STDOUT: return %.loc5_13.1
  201. // CHECK:STDOUT: }
  202. // CHECK:STDOUT: }
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: fn @Test1(%c.param_patt: %C) {
  205. // CHECK:STDOUT: !entry:
  206. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  207. // CHECK:STDOUT: %c.ref: %C = name_ref c, %c
  208. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F(constants.%C) [concrete = constants.%F.specific_fn.04a]
  209. // CHECK:STDOUT: %F.call: init %i32 = call %F.specific_fn(%c.ref)
  210. // CHECK:STDOUT: return
  211. // CHECK:STDOUT: }
  212. // CHECK:STDOUT:
  213. // CHECK:STDOUT: fn @Test2(%x.param_patt: %struct_type.m.n) {
  214. // CHECK:STDOUT: !entry:
  215. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  216. // CHECK:STDOUT: %x.ref: %struct_type.m.n = name_ref x, %x
  217. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F(constants.%struct_type.m.n) [concrete = constants.%F.specific_fn.92d]
  218. // CHECK:STDOUT: %F.call: init %i32 = call %F.specific_fn(%x.ref)
  219. // CHECK:STDOUT: return
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT:
  222. // CHECK:STDOUT: specific @F(constants.%T) {
  223. // CHECK:STDOUT: %T.loc4_15.2 => constants.%T
  224. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T.patt
  225. // CHECK:STDOUT: }
  226. // CHECK:STDOUT:
  227. // CHECK:STDOUT: specific @F(constants.%C) {
  228. // CHECK:STDOUT: %T.loc4_15.2 => constants.%C
  229. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T.patt
  230. // CHECK:STDOUT:
  231. // CHECK:STDOUT: !definition:
  232. // CHECK:STDOUT: %require_complete => constants.%complete_type.54b
  233. // CHECK:STDOUT: %.loc5_11.3 => constants.%inst.as_compatible.c0a
  234. // CHECK:STDOUT: %.loc5_11.4 => constants.%inst.splice_block.d20
  235. // CHECK:STDOUT: %.loc5_11.5 => constants.%i32
  236. // CHECK:STDOUT: %.loc5_13.2 => constants.%inst.splice_block.435
  237. // CHECK:STDOUT: }
  238. // CHECK:STDOUT:
  239. // CHECK:STDOUT: specific @F(constants.%struct_type.m.n) {
  240. // CHECK:STDOUT: %T.loc4_15.2 => constants.%struct_type.m.n
  241. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T.patt
  242. // CHECK:STDOUT:
  243. // CHECK:STDOUT: !definition:
  244. // CHECK:STDOUT: %require_complete => constants.%complete_type.622
  245. // CHECK:STDOUT: %.loc5_11.3 => constants.%inst.as_compatible.8f8
  246. // CHECK:STDOUT: %.loc5_11.4 => constants.%inst.struct_access
  247. // CHECK:STDOUT: %.loc5_11.5 => constants.%i32
  248. // CHECK:STDOUT: %.loc5_13.2 => constants.%inst.splice_block.57b
  249. // CHECK:STDOUT: }
  250. // CHECK:STDOUT:
  251. // CHECK:STDOUT: --- fail_no_such_member.carbon
  252. // CHECK:STDOUT:
  253. // CHECK:STDOUT: constants {
  254. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, template [template]
  255. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0, template [template]
  256. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  257. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  258. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  259. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  260. // CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [template]
  261. // CHECK:STDOUT: %D: type = class_type @D [concrete]
  262. // CHECK:STDOUT: %D.elem: type = unbound_element_type %D, %i32 [concrete]
  263. // CHECK:STDOUT: %struct_type.m: type = struct_type {.m: %i32} [concrete]
  264. // CHECK:STDOUT: %complete_type.218: <witness> = complete_type_witness %struct_type.m [concrete]
  265. // CHECK:STDOUT: %Test.type: type = fn_type @Test [concrete]
  266. // CHECK:STDOUT: %Test: %Test.type = struct_value () [concrete]
  267. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F, @F(%D) [concrete]
  268. // CHECK:STDOUT: %inst.as_compatible: <instruction> = inst_value [concrete] {
  269. // CHECK:STDOUT: %.63b: %D = as_compatible @F.%x.ref
  270. // CHECK:STDOUT: }
  271. // CHECK:STDOUT: %inst.name_ref: <instruction> = inst_value [concrete] {
  272. // CHECK:STDOUT: %n.ref: <error> = name_ref n, <error> [concrete = <error>]
  273. // CHECK:STDOUT: }
  274. // CHECK:STDOUT: %inst.splice_block: <instruction> = inst_value [concrete] {
  275. // CHECK:STDOUT: %.432: <error> = splice_block <error> [concrete = <error>] {}
  276. // CHECK:STDOUT: }
  277. // CHECK:STDOUT: }
  278. // CHECK:STDOUT:
  279. // CHECK:STDOUT: imports {
  280. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  281. // CHECK:STDOUT: .Int = %Core.Int
  282. // CHECK:STDOUT: import Core//prelude
  283. // CHECK:STDOUT: import Core//prelude/...
  284. // CHECK:STDOUT: }
  285. // CHECK:STDOUT: }
  286. // CHECK:STDOUT:
  287. // CHECK:STDOUT: file {
  288. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  289. // CHECK:STDOUT: .Core = imports.%Core
  290. // CHECK:STDOUT: .F = %F.decl
  291. // CHECK:STDOUT: .D = %D.decl
  292. // CHECK:STDOUT: .Test = %Test.decl
  293. // CHECK:STDOUT: }
  294. // CHECK:STDOUT: %Core.import = import Core
  295. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  296. // CHECK:STDOUT: %T.patt.loc4_15.1: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  297. // CHECK:STDOUT: %x.patt: @F.%T.loc4_15.2 (%T) = binding_pattern x
  298. // CHECK:STDOUT: %x.param_patt: @F.%T.loc4_15.2 (%T) = value_param_pattern %x.patt, call_param0
  299. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  300. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param1
  301. // CHECK:STDOUT: } {
  302. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  303. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  304. // CHECK:STDOUT: %T.loc4_15.1: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  305. // CHECK:STDOUT: %x.param: @F.%T.loc4_15.2 (%T) = value_param call_param0
  306. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc4_15.1 [template = %T.loc4_15.2 (constants.%T)]
  307. // CHECK:STDOUT: %x: @F.%T.loc4_15.2 (%T) = bind_name x, %x.param
  308. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  309. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  310. // CHECK:STDOUT: }
  311. // CHECK:STDOUT: %D.decl: type = class_decl @D [concrete = constants.%D] {} {}
  312. // CHECK:STDOUT: %Test.decl: %Test.type = fn_decl @Test [concrete = constants.%Test] {
  313. // CHECK:STDOUT: %d.patt: %D = binding_pattern d
  314. // CHECK:STDOUT: %d.param_patt: %D = value_param_pattern %d.patt, call_param0
  315. // CHECK:STDOUT: } {
  316. // CHECK:STDOUT: %d.param: %D = value_param call_param0
  317. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [concrete = constants.%D]
  318. // CHECK:STDOUT: %d: %D = bind_name d, %d.param
  319. // CHECK:STDOUT: }
  320. // CHECK:STDOUT: }
  321. // CHECK:STDOUT:
  322. // CHECK:STDOUT: class @D {
  323. // CHECK:STDOUT: %.loc12_8: %D.elem = field_decl m, element0 [concrete]
  324. // CHECK:STDOUT: name_binding_decl {
  325. // CHECK:STDOUT: %.loc12_3: %D.elem = var_pattern %.loc12_8
  326. // CHECK:STDOUT: }
  327. // CHECK:STDOUT: %.var: ref %D.elem = var <none>
  328. // CHECK:STDOUT: %struct_type.m: type = struct_type {.m: %i32} [concrete = constants.%struct_type.m]
  329. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.m [concrete = constants.%complete_type.218]
  330. // CHECK:STDOUT: complete_type_witness = %complete_type
  331. // CHECK:STDOUT:
  332. // CHECK:STDOUT: !members:
  333. // CHECK:STDOUT: .Self = constants.%D
  334. // CHECK:STDOUT: .m = %.loc12_8
  335. // CHECK:STDOUT: .n = <poisoned>
  336. // CHECK:STDOUT: }
  337. // CHECK:STDOUT:
  338. // CHECK:STDOUT: generic fn @F(%T.loc4_15.1: type) {
  339. // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  340. // CHECK:STDOUT: %T.patt.loc4_15.2: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  341. // CHECK:STDOUT:
  342. // CHECK:STDOUT: !definition:
  343. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T.loc4_15.2 [template = %require_complete (constants.%require_complete.4ae)]
  344. // CHECK:STDOUT: %.loc8_11.3: <instruction> = refine_type_action %x.ref, %T.loc4_15.2 [template]
  345. // CHECK:STDOUT: %.loc8_11.4: <instruction> = access_member_action %.loc8_11.1, n [template]
  346. // CHECK:STDOUT: %.loc8_11.5: type = type_of_inst %.loc8_11.4 [template]
  347. // CHECK:STDOUT: %.loc8_13.2: <instruction> = convert_to_value_action %.loc8_11.2, constants.%i32 [template]
  348. // CHECK:STDOUT:
  349. // CHECK:STDOUT: fn[%T.patt.loc4_15.1: type](%x.param_patt: @F.%T.loc4_15.2 (%T)) -> %i32 {
  350. // CHECK:STDOUT: !entry:
  351. // CHECK:STDOUT: %x.ref: @F.%T.loc4_15.2 (%T) = name_ref x, %x
  352. // CHECK:STDOUT: %.loc8_11.1: @F.%T.loc4_15.2 (%T) = splice_inst %.loc8_11.3
  353. // CHECK:STDOUT: %.loc8_11.2: @F.%.loc8_11.5 (@F.%.loc8_11.5) = splice_inst %.loc8_11.4
  354. // CHECK:STDOUT: %.loc8_13.1: %i32 = splice_inst %.loc8_13.2
  355. // CHECK:STDOUT: return %.loc8_13.1
  356. // CHECK:STDOUT: }
  357. // CHECK:STDOUT: }
  358. // CHECK:STDOUT:
  359. // CHECK:STDOUT: fn @Test(%d.param_patt: %D) {
  360. // CHECK:STDOUT: !entry:
  361. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  362. // CHECK:STDOUT: %d.ref: %D = name_ref d, %d
  363. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F(constants.%D) [concrete = constants.%F.specific_fn]
  364. // CHECK:STDOUT: %F.call: init %i32 = call %F.specific_fn(%d.ref)
  365. // CHECK:STDOUT: return
  366. // CHECK:STDOUT: }
  367. // CHECK:STDOUT:
  368. // CHECK:STDOUT: specific @F(constants.%T) {
  369. // CHECK:STDOUT: %T.loc4_15.2 => constants.%T
  370. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T.patt
  371. // CHECK:STDOUT: }
  372. // CHECK:STDOUT:
  373. // CHECK:STDOUT: specific @F(constants.%D) {
  374. // CHECK:STDOUT: %T.loc4_15.2 => constants.%D
  375. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T.patt
  376. // CHECK:STDOUT:
  377. // CHECK:STDOUT: !definition:
  378. // CHECK:STDOUT: %require_complete => constants.%complete_type.218
  379. // CHECK:STDOUT: %.loc8_11.3 => constants.%inst.as_compatible
  380. // CHECK:STDOUT: %.loc8_11.4 => constants.%inst.name_ref
  381. // CHECK:STDOUT: %.loc8_11.5 => <error>
  382. // CHECK:STDOUT: %.loc8_13.2 => constants.%inst.splice_block
  383. // CHECK:STDOUT: }
  384. // CHECK:STDOUT:
  385. // CHECK:STDOUT: --- fail_member_wrong_type.carbon
  386. // CHECK:STDOUT:
  387. // CHECK:STDOUT: constants {
  388. // CHECK:STDOUT: %T: type = bind_symbolic_name T, 0, template [template]
  389. // CHECK:STDOUT: %T.patt: type = symbolic_binding_pattern T, 0, template [template]
  390. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  391. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  392. // CHECK:STDOUT: %F.type: type = fn_type @F.1 [concrete]
  393. // CHECK:STDOUT: %F.c41: %F.type = struct_value () [concrete]
  394. // CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [template]
  395. // CHECK:STDOUT: %E: type = class_type @E [concrete]
  396. // CHECK:STDOUT: %F.a8a: type = class_type @F.2 [concrete]
  397. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  398. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
  399. // CHECK:STDOUT: %E.elem: type = unbound_element_type %E, %F.a8a [concrete]
  400. // CHECK:STDOUT: %struct_type.n.e4c: type = struct_type {.n: %F.a8a} [concrete]
  401. // CHECK:STDOUT: %complete_type.5ba: <witness> = complete_type_witness %struct_type.n.e4c [concrete]
  402. // CHECK:STDOUT: %Test.type: type = fn_type @Test [concrete]
  403. // CHECK:STDOUT: %Test: %Test.type = struct_value () [concrete]
  404. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.c41, @F.1(%E) [concrete]
  405. // CHECK:STDOUT: %inst.as_compatible: <instruction> = inst_value [concrete] {
  406. // CHECK:STDOUT: %.a66: %E = as_compatible @F.1.%x.ref
  407. // CHECK:STDOUT: }
  408. // CHECK:STDOUT: %inst.splice_block.2a2: <instruction> = inst_value [concrete] {
  409. // CHECK:STDOUT: %.6c9: %F.a8a = splice_block %.e29 {
  410. // CHECK:STDOUT: %n.ref: %E.elem = name_ref n, @E.%.loc16_8 [concrete = @E.%.loc16_8]
  411. // CHECK:STDOUT: %.999: ref %F.a8a = class_element_access %.a66, element0
  412. // CHECK:STDOUT: %.e29: %F.a8a = bind_value %.999
  413. // CHECK:STDOUT: }
  414. // CHECK:STDOUT: }
  415. // CHECK:STDOUT: %inst.splice_block.a04: <instruction> = inst_value [concrete] {
  416. // CHECK:STDOUT: %.31f: <error> = splice_block <error> [concrete = <error>] {
  417. // CHECK:STDOUT: %.fd6: %i32 = converted %.6c9, <error> [concrete = <error>]
  418. // CHECK:STDOUT: }
  419. // CHECK:STDOUT: }
  420. // CHECK:STDOUT: }
  421. // CHECK:STDOUT:
  422. // CHECK:STDOUT: imports {
  423. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  424. // CHECK:STDOUT: .Int = %Core.Int
  425. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  426. // CHECK:STDOUT: import Core//prelude
  427. // CHECK:STDOUT: import Core//prelude/...
  428. // CHECK:STDOUT: }
  429. // CHECK:STDOUT: }
  430. // CHECK:STDOUT:
  431. // CHECK:STDOUT: file {
  432. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  433. // CHECK:STDOUT: .Core = imports.%Core
  434. // CHECK:STDOUT: .F = %F.decl
  435. // CHECK:STDOUT: .E = %E.decl
  436. // CHECK:STDOUT: .Test = %Test.decl
  437. // CHECK:STDOUT: }
  438. // CHECK:STDOUT: %Core.import = import Core
  439. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F.1 [concrete = constants.%F.c41] {
  440. // CHECK:STDOUT: %T.patt.loc4_15.1: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  441. // CHECK:STDOUT: %x.patt: @F.1.%T.loc4_15.2 (%T) = binding_pattern x
  442. // CHECK:STDOUT: %x.param_patt: @F.1.%T.loc4_15.2 (%T) = value_param_pattern %x.patt, call_param0
  443. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  444. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param1
  445. // CHECK:STDOUT: } {
  446. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  447. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  448. // CHECK:STDOUT: %T.loc4_15.1: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  449. // CHECK:STDOUT: %x.param: @F.1.%T.loc4_15.2 (%T) = value_param call_param0
  450. // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc4_15.1 [template = %T.loc4_15.2 (constants.%T)]
  451. // CHECK:STDOUT: %x: @F.1.%T.loc4_15.2 (%T) = bind_name x, %x.param
  452. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  453. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  454. // CHECK:STDOUT: }
  455. // CHECK:STDOUT: %E.decl: type = class_decl @E [concrete = constants.%E] {} {}
  456. // CHECK:STDOUT: %Test.decl: %Test.type = fn_decl @Test [concrete = constants.%Test] {
  457. // CHECK:STDOUT: %e.patt: %E = binding_pattern e
  458. // CHECK:STDOUT: %e.param_patt: %E = value_param_pattern %e.patt, call_param0
  459. // CHECK:STDOUT: } {
  460. // CHECK:STDOUT: %e.param: %E = value_param call_param0
  461. // CHECK:STDOUT: %E.ref: type = name_ref E, file.%E.decl [concrete = constants.%E]
  462. // CHECK:STDOUT: %e: %E = bind_name e, %e.param
  463. // CHECK:STDOUT: }
  464. // CHECK:STDOUT: }
  465. // CHECK:STDOUT:
  466. // CHECK:STDOUT: class @E {
  467. // CHECK:STDOUT: %F.decl: type = class_decl @F.2 [concrete = constants.%F.a8a] {} {}
  468. // CHECK:STDOUT: %.loc16_8: %E.elem = field_decl n, element0 [concrete]
  469. // CHECK:STDOUT: name_binding_decl {
  470. // CHECK:STDOUT: %.loc16_3: %E.elem = var_pattern %.loc16_8
  471. // CHECK:STDOUT: }
  472. // CHECK:STDOUT: %.var: ref %E.elem = var <none>
  473. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %F.a8a} [concrete = constants.%struct_type.n.e4c]
  474. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.5ba]
  475. // CHECK:STDOUT: complete_type_witness = %complete_type
  476. // CHECK:STDOUT:
  477. // CHECK:STDOUT: !members:
  478. // CHECK:STDOUT: .Self = constants.%E
  479. // CHECK:STDOUT: .F = %F.decl
  480. // CHECK:STDOUT: .n = %.loc16_8
  481. // CHECK:STDOUT: }
  482. // CHECK:STDOUT:
  483. // CHECK:STDOUT: class @F.2 {
  484. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete = constants.%empty_struct_type]
  485. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type.357]
  486. // CHECK:STDOUT: complete_type_witness = %complete_type
  487. // CHECK:STDOUT:
  488. // CHECK:STDOUT: !members:
  489. // CHECK:STDOUT: .Self = constants.%F.a8a
  490. // CHECK:STDOUT: }
  491. // CHECK:STDOUT:
  492. // CHECK:STDOUT: generic fn @F.1(%T.loc4_15.1: type) {
  493. // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T, 0, template [template = %T.loc4_15.2 (constants.%T)]
  494. // CHECK:STDOUT: %T.patt.loc4_15.2: type = symbolic_binding_pattern T, 0, template [template = %T.patt.loc4_15.2 (constants.%T.patt)]
  495. // CHECK:STDOUT:
  496. // CHECK:STDOUT: !definition:
  497. // CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T.loc4_15.2 [template = %require_complete (constants.%require_complete.4ae)]
  498. // CHECK:STDOUT: %.loc11_11.3: <instruction> = refine_type_action %x.ref, %T.loc4_15.2 [template]
  499. // CHECK:STDOUT: %.loc11_11.4: <instruction> = access_member_action %.loc11_11.1, n [template]
  500. // CHECK:STDOUT: %.loc11_11.5: type = type_of_inst %.loc11_11.4 [template]
  501. // CHECK:STDOUT: %.loc11_13.2: <instruction> = convert_to_value_action %.loc11_11.2, constants.%i32 [template]
  502. // CHECK:STDOUT:
  503. // CHECK:STDOUT: fn[%T.patt.loc4_15.1: type](%x.param_patt: @F.1.%T.loc4_15.2 (%T)) -> %i32 {
  504. // CHECK:STDOUT: !entry:
  505. // CHECK:STDOUT: %x.ref: @F.1.%T.loc4_15.2 (%T) = name_ref x, %x
  506. // CHECK:STDOUT: %.loc11_11.1: @F.1.%T.loc4_15.2 (%T) = splice_inst %.loc11_11.3
  507. // CHECK:STDOUT: %.loc11_11.2: @F.1.%.loc11_11.5 (@F.1.%.loc11_11.5) = splice_inst %.loc11_11.4
  508. // CHECK:STDOUT: %.loc11_13.1: %i32 = splice_inst %.loc11_13.2
  509. // CHECK:STDOUT: return %.loc11_13.1
  510. // CHECK:STDOUT: }
  511. // CHECK:STDOUT: }
  512. // CHECK:STDOUT:
  513. // CHECK:STDOUT: fn @Test(%e.param_patt: %E) {
  514. // CHECK:STDOUT: !entry:
  515. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F.c41]
  516. // CHECK:STDOUT: %e.ref: %E = name_ref e, %e
  517. // CHECK:STDOUT: %F.specific_fn: <specific function> = specific_function %F.ref, @F.1(constants.%E) [concrete = constants.%F.specific_fn]
  518. // CHECK:STDOUT: %F.call: init %i32 = call %F.specific_fn(%e.ref)
  519. // CHECK:STDOUT: return
  520. // CHECK:STDOUT: }
  521. // CHECK:STDOUT:
  522. // CHECK:STDOUT: specific @F.1(constants.%T) {
  523. // CHECK:STDOUT: %T.loc4_15.2 => constants.%T
  524. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T.patt
  525. // CHECK:STDOUT: }
  526. // CHECK:STDOUT:
  527. // CHECK:STDOUT: specific @F.1(constants.%E) {
  528. // CHECK:STDOUT: %T.loc4_15.2 => constants.%E
  529. // CHECK:STDOUT: %T.patt.loc4_15.2 => constants.%T.patt
  530. // CHECK:STDOUT:
  531. // CHECK:STDOUT: !definition:
  532. // CHECK:STDOUT: %require_complete => constants.%complete_type.5ba
  533. // CHECK:STDOUT: %.loc11_11.3 => constants.%inst.as_compatible
  534. // CHECK:STDOUT: %.loc11_11.4 => constants.%inst.splice_block.2a2
  535. // CHECK:STDOUT: %.loc11_11.5 => constants.%F.a8a
  536. // CHECK:STDOUT: %.loc11_13.2 => constants.%inst.splice_block.a04
  537. // CHECK:STDOUT: }
  538. // CHECK:STDOUT: