base_method_shadow.carbon 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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/base_method_shadow.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/base_method_shadow.carbon
  10. base class A {
  11. fn F[addr self: Self*]();
  12. }
  13. base class B {
  14. extend base: A;
  15. fn F[addr self: Self*]();
  16. }
  17. class C {
  18. extend base: B;
  19. fn F[addr self: Self*]();
  20. }
  21. class D {
  22. extend base: B;
  23. }
  24. fn Call(a: A*, b: B*, c: C*, d: D*) {
  25. (*a).F();
  26. (*b).F();
  27. (*c).F();
  28. (*d).F();
  29. }
  30. // CHECK:STDOUT: --- base_method_shadow.carbon
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: constants {
  33. // CHECK:STDOUT: %A: type = class_type @A [template]
  34. // CHECK:STDOUT: %ptr.6db: type = ptr_type %A [template]
  35. // CHECK:STDOUT: %F.type.649: type = fn_type @F.1 [template]
  36. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
  37. // CHECK:STDOUT: %F.485: %F.type.649 = struct_value () [template]
  38. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  39. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  40. // CHECK:STDOUT: %B: type = class_type @B [template]
  41. // CHECK:STDOUT: %B.elem: type = unbound_element_type %B, %A [template]
  42. // CHECK:STDOUT: %ptr.e79: type = ptr_type %B [template]
  43. // CHECK:STDOUT: %F.type.8c6: type = fn_type @F.2 [template]
  44. // CHECK:STDOUT: %F.92a: %F.type.8c6 = struct_value () [template]
  45. // CHECK:STDOUT: %struct_type.base.953: type = struct_type {.base: %A} [template]
  46. // CHECK:STDOUT: %complete_type.020: <witness> = complete_type_witness %struct_type.base.953 [template]
  47. // CHECK:STDOUT: %C: type = class_type @C [template]
  48. // CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %B [template]
  49. // CHECK:STDOUT: %ptr.019: type = ptr_type %C [template]
  50. // CHECK:STDOUT: %F.type.c29: type = fn_type @F.3 [template]
  51. // CHECK:STDOUT: %F.437: %F.type.c29 = struct_value () [template]
  52. // CHECK:STDOUT: %struct_type.base.0ff: type = struct_type {.base: %B} [template]
  53. // CHECK:STDOUT: %complete_type.98e: <witness> = complete_type_witness %struct_type.base.0ff [template]
  54. // CHECK:STDOUT: %D: type = class_type @D [template]
  55. // CHECK:STDOUT: %D.elem: type = unbound_element_type %D, %B [template]
  56. // CHECK:STDOUT: %ptr.19c: type = ptr_type %D [template]
  57. // CHECK:STDOUT: %Call.type: type = fn_type @Call [template]
  58. // CHECK:STDOUT: %Call: %Call.type = struct_value () [template]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: imports {
  62. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  63. // CHECK:STDOUT: import Core//prelude
  64. // CHECK:STDOUT: import Core//prelude/...
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: file {
  69. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  70. // CHECK:STDOUT: .Core = imports.%Core
  71. // CHECK:STDOUT: .A = %A.decl
  72. // CHECK:STDOUT: .B = %B.decl
  73. // CHECK:STDOUT: .C = %C.decl
  74. // CHECK:STDOUT: .D = %D.decl
  75. // CHECK:STDOUT: .Call = %Call.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %Core.import = import Core
  78. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {} {}
  79. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {}
  80. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  81. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {} {}
  82. // CHECK:STDOUT: %Call.decl: %Call.type = fn_decl @Call [template = constants.%Call] {
  83. // CHECK:STDOUT: %a.patt: %ptr.6db = binding_pattern a
  84. // CHECK:STDOUT: %a.param_patt: %ptr.6db = value_param_pattern %a.patt, runtime_param0
  85. // CHECK:STDOUT: %b.patt: %ptr.e79 = binding_pattern b
  86. // CHECK:STDOUT: %b.param_patt: %ptr.e79 = value_param_pattern %b.patt, runtime_param1
  87. // CHECK:STDOUT: %c.patt: %ptr.019 = binding_pattern c
  88. // CHECK:STDOUT: %c.param_patt: %ptr.019 = value_param_pattern %c.patt, runtime_param2
  89. // CHECK:STDOUT: %d.patt: %ptr.19c = binding_pattern d
  90. // CHECK:STDOUT: %d.param_patt: %ptr.19c = value_param_pattern %d.patt, runtime_param3
  91. // CHECK:STDOUT: } {
  92. // CHECK:STDOUT: %a.param: %ptr.6db = value_param runtime_param0
  93. // CHECK:STDOUT: %.loc29_13: type = splice_block %ptr.loc29_13 [template = constants.%ptr.6db] {
  94. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  95. // CHECK:STDOUT: %ptr.loc29_13: type = ptr_type %A [template = constants.%ptr.6db]
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT: %a: %ptr.6db = bind_name a, %a.param
  98. // CHECK:STDOUT: %b.param: %ptr.e79 = value_param runtime_param1
  99. // CHECK:STDOUT: %.loc29_20: type = splice_block %ptr.loc29_20 [template = constants.%ptr.e79] {
  100. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  101. // CHECK:STDOUT: %ptr.loc29_20: type = ptr_type %B [template = constants.%ptr.e79]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %b: %ptr.e79 = bind_name b, %b.param
  104. // CHECK:STDOUT: %c.param: %ptr.019 = value_param runtime_param2
  105. // CHECK:STDOUT: %.loc29_27: type = splice_block %ptr.loc29_27 [template = constants.%ptr.019] {
  106. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  107. // CHECK:STDOUT: %ptr.loc29_27: type = ptr_type %C [template = constants.%ptr.019]
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: %c: %ptr.019 = bind_name c, %c.param
  110. // CHECK:STDOUT: %d.param: %ptr.19c = value_param runtime_param3
  111. // CHECK:STDOUT: %.loc29_34: type = splice_block %ptr.loc29_34 [template = constants.%ptr.19c] {
  112. // CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [template = constants.%D]
  113. // CHECK:STDOUT: %ptr.loc29_34: type = ptr_type %D [template = constants.%ptr.19c]
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT: %d: %ptr.19c = bind_name d, %d.param
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT:
  119. // CHECK:STDOUT: class @A {
  120. // CHECK:STDOUT: %F.decl: %F.type.649 = fn_decl @F.1 [template = constants.%F.485] {
  121. // CHECK:STDOUT: %self.patt: %ptr.6db = binding_pattern self
  122. // CHECK:STDOUT: %self.param_patt: %ptr.6db = value_param_pattern %self.patt, runtime_param0
  123. // CHECK:STDOUT: %.loc12_8: auto = addr_pattern %self.param_patt
  124. // CHECK:STDOUT: } {
  125. // CHECK:STDOUT: %self.param: %ptr.6db = value_param runtime_param0
  126. // CHECK:STDOUT: %.loc12_23: type = splice_block %ptr [template = constants.%ptr.6db] {
  127. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%A [template = constants.%A]
  128. // CHECK:STDOUT: %ptr: type = ptr_type %A [template = constants.%ptr.6db]
  129. // CHECK:STDOUT: }
  130. // CHECK:STDOUT: %self: %ptr.6db = bind_name self, %self.param
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  133. // CHECK:STDOUT: complete_type_witness = %complete_type
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: !members:
  136. // CHECK:STDOUT: .Self = constants.%A
  137. // CHECK:STDOUT: .F = %F.decl
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: class @B {
  141. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  142. // CHECK:STDOUT: %.loc16: %B.elem = base_decl %A.ref, element0 [template]
  143. // CHECK:STDOUT: %F.decl: %F.type.8c6 = fn_decl @F.2 [template = constants.%F.92a] {
  144. // CHECK:STDOUT: %self.patt: %ptr.e79 = binding_pattern self
  145. // CHECK:STDOUT: %self.param_patt: %ptr.e79 = value_param_pattern %self.patt, runtime_param0
  146. // CHECK:STDOUT: %.loc17_8: auto = addr_pattern %self.param_patt
  147. // CHECK:STDOUT: } {
  148. // CHECK:STDOUT: %self.param: %ptr.e79 = value_param runtime_param0
  149. // CHECK:STDOUT: %.loc17_23: type = splice_block %ptr [template = constants.%ptr.e79] {
  150. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%B [template = constants.%B]
  151. // CHECK:STDOUT: %ptr: type = ptr_type %B [template = constants.%ptr.e79]
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT: %self: %ptr.e79 = bind_name self, %self.param
  154. // CHECK:STDOUT: }
  155. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base.953 [template = constants.%complete_type.020]
  156. // CHECK:STDOUT: complete_type_witness = %complete_type
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: !members:
  159. // CHECK:STDOUT: .Self = constants.%B
  160. // CHECK:STDOUT: .base = %.loc16
  161. // CHECK:STDOUT: .F = %F.decl
  162. // CHECK:STDOUT: extend %A.ref
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: class @C {
  166. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  167. // CHECK:STDOUT: %.loc21: %C.elem = base_decl %B.ref, element0 [template]
  168. // CHECK:STDOUT: %F.decl: %F.type.c29 = fn_decl @F.3 [template = constants.%F.437] {
  169. // CHECK:STDOUT: %self.patt: %ptr.019 = binding_pattern self
  170. // CHECK:STDOUT: %self.param_patt: %ptr.019 = value_param_pattern %self.patt, runtime_param0
  171. // CHECK:STDOUT: %.loc22_8: auto = addr_pattern %self.param_patt
  172. // CHECK:STDOUT: } {
  173. // CHECK:STDOUT: %self.param: %ptr.019 = value_param runtime_param0
  174. // CHECK:STDOUT: %.loc22_23: type = splice_block %ptr [template = constants.%ptr.019] {
  175. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  176. // CHECK:STDOUT: %ptr: type = ptr_type %C [template = constants.%ptr.019]
  177. // CHECK:STDOUT: }
  178. // CHECK:STDOUT: %self: %ptr.019 = bind_name self, %self.param
  179. // CHECK:STDOUT: }
  180. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base.0ff [template = constants.%complete_type.98e]
  181. // CHECK:STDOUT: complete_type_witness = %complete_type
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: !members:
  184. // CHECK:STDOUT: .Self = constants.%C
  185. // CHECK:STDOUT: .base = %.loc21
  186. // CHECK:STDOUT: .F = %F.decl
  187. // CHECK:STDOUT: extend %B.ref
  188. // CHECK:STDOUT: }
  189. // CHECK:STDOUT:
  190. // CHECK:STDOUT: class @D {
  191. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  192. // CHECK:STDOUT: %.loc26: %D.elem = base_decl %B.ref, element0 [template]
  193. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.base.0ff [template = constants.%complete_type.98e]
  194. // CHECK:STDOUT: complete_type_witness = %complete_type
  195. // CHECK:STDOUT:
  196. // CHECK:STDOUT: !members:
  197. // CHECK:STDOUT: .Self = constants.%D
  198. // CHECK:STDOUT: .base = %.loc26
  199. // CHECK:STDOUT: extend %B.ref
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: fn @F.1[addr %self.param_patt: %ptr.6db]();
  203. // CHECK:STDOUT:
  204. // CHECK:STDOUT: fn @F.2[addr %self.param_patt: %ptr.e79]();
  205. // CHECK:STDOUT:
  206. // CHECK:STDOUT: fn @F.3[addr %self.param_patt: %ptr.019]();
  207. // CHECK:STDOUT:
  208. // CHECK:STDOUT: fn @Call(%a.param_patt: %ptr.6db, %b.param_patt: %ptr.e79, %c.param_patt: %ptr.019, %d.param_patt: %ptr.19c) {
  209. // CHECK:STDOUT: !entry:
  210. // CHECK:STDOUT: %a.ref: %ptr.6db = name_ref a, %a
  211. // CHECK:STDOUT: %.loc30: ref %A = deref %a.ref
  212. // CHECK:STDOUT: %F.ref.loc30: %F.type.649 = name_ref F, @A.%F.decl [template = constants.%F.485]
  213. // CHECK:STDOUT: %F.bound.loc30: <bound method> = bound_method %.loc30, %F.ref.loc30
  214. // CHECK:STDOUT: %addr.loc30: %ptr.6db = addr_of %.loc30
  215. // CHECK:STDOUT: %F.call.loc30: init %empty_tuple.type = call %F.bound.loc30(%addr.loc30)
  216. // CHECK:STDOUT: %b.ref: %ptr.e79 = name_ref b, %b
  217. // CHECK:STDOUT: %.loc31: ref %B = deref %b.ref
  218. // CHECK:STDOUT: %F.ref.loc31: %F.type.8c6 = name_ref F, @B.%F.decl [template = constants.%F.92a]
  219. // CHECK:STDOUT: %F.bound.loc31: <bound method> = bound_method %.loc31, %F.ref.loc31
  220. // CHECK:STDOUT: %addr.loc31: %ptr.e79 = addr_of %.loc31
  221. // CHECK:STDOUT: %F.call.loc31: init %empty_tuple.type = call %F.bound.loc31(%addr.loc31)
  222. // CHECK:STDOUT: %c.ref: %ptr.019 = name_ref c, %c
  223. // CHECK:STDOUT: %.loc32: ref %C = deref %c.ref
  224. // CHECK:STDOUT: %F.ref.loc32: %F.type.c29 = name_ref F, @C.%F.decl [template = constants.%F.437]
  225. // CHECK:STDOUT: %F.bound.loc32: <bound method> = bound_method %.loc32, %F.ref.loc32
  226. // CHECK:STDOUT: %addr.loc32: %ptr.019 = addr_of %.loc32
  227. // CHECK:STDOUT: %F.call.loc32: init %empty_tuple.type = call %F.bound.loc32(%addr.loc32)
  228. // CHECK:STDOUT: %d.ref: %ptr.19c = name_ref d, %d
  229. // CHECK:STDOUT: %.loc33_4.1: ref %D = deref %d.ref
  230. // CHECK:STDOUT: %F.ref.loc33: %F.type.8c6 = name_ref F, @B.%F.decl [template = constants.%F.92a]
  231. // CHECK:STDOUT: %F.bound.loc33: <bound method> = bound_method %.loc33_4.1, %F.ref.loc33
  232. // CHECK:STDOUT: %addr.loc33_4.1: %ptr.19c = addr_of %.loc33_4.1
  233. // CHECK:STDOUT: %.loc33_4.2: ref %D = deref %addr.loc33_4.1
  234. // CHECK:STDOUT: %.loc33_4.3: ref %B = class_element_access %.loc33_4.2, element0
  235. // CHECK:STDOUT: %addr.loc33_4.2: %ptr.e79 = addr_of %.loc33_4.3
  236. // CHECK:STDOUT: %.loc33_4.4: %ptr.e79 = converted %addr.loc33_4.1, %addr.loc33_4.2
  237. // CHECK:STDOUT: %F.call.loc33: init %empty_tuple.type = call %F.bound.loc33(%.loc33_4.4)
  238. // CHECK:STDOUT: return
  239. // CHECK:STDOUT: }
  240. // CHECK:STDOUT: