base_method_shadow.carbon 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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: %.1: type = ptr_type %A [template]
  35. // CHECK:STDOUT: %F.type.1: type = fn_type @F.1 [template]
  36. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  37. // CHECK:STDOUT: %F.1: %F.type.1 = struct_value () [template]
  38. // CHECK:STDOUT: %.3: type = struct_type {} [template]
  39. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  40. // CHECK:STDOUT: %B: type = class_type @B [template]
  41. // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
  42. // CHECK:STDOUT: %.6: type = unbound_element_type %B, %A [template]
  43. // CHECK:STDOUT: %.7: type = ptr_type %B [template]
  44. // CHECK:STDOUT: %F.type.2: type = fn_type @F.2 [template]
  45. // CHECK:STDOUT: %F.2: %F.type.2 = struct_value () [template]
  46. // CHECK:STDOUT: %.8: type = struct_type {.base: %A} [template]
  47. // CHECK:STDOUT: %.9: <witness> = complete_type_witness %.8 [template]
  48. // CHECK:STDOUT: %C: type = class_type @C [template]
  49. // CHECK:STDOUT: %.10: type = struct_type {.base: %.5} [template]
  50. // CHECK:STDOUT: %.11: type = ptr_type %.8 [template]
  51. // CHECK:STDOUT: %.12: type = unbound_element_type %C, %B [template]
  52. // CHECK:STDOUT: %.13: type = ptr_type %C [template]
  53. // CHECK:STDOUT: %F.type.3: type = fn_type @F.3 [template]
  54. // CHECK:STDOUT: %F.3: %F.type.3 = struct_value () [template]
  55. // CHECK:STDOUT: %.14: type = struct_type {.base: %B} [template]
  56. // CHECK:STDOUT: %.15: <witness> = complete_type_witness %.14 [template]
  57. // CHECK:STDOUT: %D: type = class_type @D [template]
  58. // CHECK:STDOUT: %.16: type = unbound_element_type %D, %B [template]
  59. // CHECK:STDOUT: %.17: type = ptr_type %D [template]
  60. // CHECK:STDOUT: %Call.type: type = fn_type @Call [template]
  61. // CHECK:STDOUT: %Call: %Call.type = struct_value () [template]
  62. // CHECK:STDOUT: %.18: type = struct_type {.base: %.11} [template]
  63. // CHECK:STDOUT: %.19: type = ptr_type %.14 [template]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: imports {
  67. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  68. // CHECK:STDOUT: import Core//prelude
  69. // CHECK:STDOUT: import Core//prelude/operators
  70. // CHECK:STDOUT: import Core//prelude/types
  71. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  72. // CHECK:STDOUT: import Core//prelude/operators/as
  73. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  74. // CHECK:STDOUT: import Core//prelude/operators/comparison
  75. // CHECK:STDOUT: import Core//prelude/types/bool
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: file {
  80. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  81. // CHECK:STDOUT: .Core = imports.%Core
  82. // CHECK:STDOUT: .A = %A.decl
  83. // CHECK:STDOUT: .B = %B.decl
  84. // CHECK:STDOUT: .C = %C.decl
  85. // CHECK:STDOUT: .D = %D.decl
  86. // CHECK:STDOUT: .Call = %Call.decl
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %Core.import = import Core
  89. // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
  90. // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {}
  91. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  92. // CHECK:STDOUT: %D.decl: type = class_decl @D [template = constants.%D] {}
  93. // CHECK:STDOUT: %Call.decl: %Call.type = fn_decl @Call [template = constants.%Call] {
  94. // CHECK:STDOUT: %A.ref: type = name_ref A, %A.decl [template = constants.%A]
  95. // CHECK:STDOUT: %.loc29_13: type = ptr_type %A [template = constants.%.1]
  96. // CHECK:STDOUT: %a.loc29_9.1: %.1 = param a, runtime_param0
  97. // CHECK:STDOUT: @Call.%a: %.1 = bind_name a, %a.loc29_9.1
  98. // CHECK:STDOUT: %B.ref: type = name_ref B, %B.decl [template = constants.%B]
  99. // CHECK:STDOUT: %.loc29_20: type = ptr_type %B [template = constants.%.7]
  100. // CHECK:STDOUT: %b.loc29_16.1: %.7 = param b, runtime_param1
  101. // CHECK:STDOUT: @Call.%b: %.7 = bind_name b, %b.loc29_16.1
  102. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  103. // CHECK:STDOUT: %.loc29_27: type = ptr_type %C [template = constants.%.13]
  104. // CHECK:STDOUT: %c.loc29_23.1: %.13 = param c, runtime_param2
  105. // CHECK:STDOUT: @Call.%c: %.13 = bind_name c, %c.loc29_23.1
  106. // CHECK:STDOUT: %D.ref: type = name_ref D, %D.decl [template = constants.%D]
  107. // CHECK:STDOUT: %.loc29_34: type = ptr_type %D [template = constants.%.17]
  108. // CHECK:STDOUT: %d.loc29_30.1: %.17 = param d, runtime_param3
  109. // CHECK:STDOUT: @Call.%d: %.17 = bind_name d, %d.loc29_30.1
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: class @A {
  114. // CHECK:STDOUT: %F.decl: %F.type.1 = fn_decl @F.1 [template = constants.%F.1] {
  115. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%A [template = constants.%A]
  116. // CHECK:STDOUT: %.loc12_23: type = ptr_type %A [template = constants.%.1]
  117. // CHECK:STDOUT: %self.loc12_13.1: %.1 = param self, runtime_param0
  118. // CHECK:STDOUT: %self.loc12_13.3: %.1 = bind_name self, %self.loc12_13.1
  119. // CHECK:STDOUT: %.loc12_8: %.1 = addr_pattern %self.loc12_13.3
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %.loc13: <witness> = complete_type_witness %.3 [template = constants.%.4]
  122. // CHECK:STDOUT:
  123. // CHECK:STDOUT: !members:
  124. // CHECK:STDOUT: .Self = constants.%A
  125. // CHECK:STDOUT: .F = %F.decl
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: class @B {
  129. // CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [template = constants.%A]
  130. // CHECK:STDOUT: %.loc16: %.6 = base_decl %A, element0 [template]
  131. // CHECK:STDOUT: %F.decl: %F.type.2 = fn_decl @F.2 [template = constants.%F.2] {
  132. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%B [template = constants.%B]
  133. // CHECK:STDOUT: %.loc17_23: type = ptr_type %B [template = constants.%.7]
  134. // CHECK:STDOUT: %self.loc17_13.1: %.7 = param self, runtime_param0
  135. // CHECK:STDOUT: %self.loc17_13.3: %.7 = bind_name self, %self.loc17_13.1
  136. // CHECK:STDOUT: %.loc17_8: %.7 = addr_pattern %self.loc17_13.3
  137. // CHECK:STDOUT: }
  138. // CHECK:STDOUT: %.loc18: <witness> = complete_type_witness %.8 [template = constants.%.9]
  139. // CHECK:STDOUT:
  140. // CHECK:STDOUT: !members:
  141. // CHECK:STDOUT: .Self = constants.%B
  142. // CHECK:STDOUT: .base = %.loc16
  143. // CHECK:STDOUT: .F = %F.decl
  144. // CHECK:STDOUT: extend name_scope2
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT:
  147. // CHECK:STDOUT: class @C {
  148. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  149. // CHECK:STDOUT: %.loc21: %.12 = base_decl %B, element0 [template]
  150. // CHECK:STDOUT: %F.decl: %F.type.3 = fn_decl @F.3 [template = constants.%F.3] {
  151. // CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [template = constants.%C]
  152. // CHECK:STDOUT: %.loc22_23: type = ptr_type %C [template = constants.%.13]
  153. // CHECK:STDOUT: %self.loc22_13.1: %.13 = param self, runtime_param0
  154. // CHECK:STDOUT: %self.loc22_13.3: %.13 = bind_name self, %self.loc22_13.1
  155. // CHECK:STDOUT: %.loc22_8: %.13 = addr_pattern %self.loc22_13.3
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT: %.loc23: <witness> = complete_type_witness %.14 [template = constants.%.15]
  158. // CHECK:STDOUT:
  159. // CHECK:STDOUT: !members:
  160. // CHECK:STDOUT: .Self = constants.%C
  161. // CHECK:STDOUT: .base = %.loc21
  162. // CHECK:STDOUT: .F = %F.decl
  163. // CHECK:STDOUT: extend name_scope3
  164. // CHECK:STDOUT: }
  165. // CHECK:STDOUT:
  166. // CHECK:STDOUT: class @D {
  167. // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B]
  168. // CHECK:STDOUT: %.loc26: %.16 = base_decl %B, element0 [template]
  169. // CHECK:STDOUT: %.loc27: <witness> = complete_type_witness %.14 [template = constants.%.15]
  170. // CHECK:STDOUT:
  171. // CHECK:STDOUT: !members:
  172. // CHECK:STDOUT: .Self = constants.%D
  173. // CHECK:STDOUT: .base = %.loc26
  174. // CHECK:STDOUT: extend name_scope3
  175. // CHECK:STDOUT: }
  176. // CHECK:STDOUT:
  177. // CHECK:STDOUT: fn @F.1[addr @A.%self.loc12_13.3: %.1]();
  178. // CHECK:STDOUT:
  179. // CHECK:STDOUT: fn @F.2[addr @B.%self.loc17_13.3: %.7]();
  180. // CHECK:STDOUT:
  181. // CHECK:STDOUT: fn @F.3[addr @C.%self.loc22_13.3: %.13]();
  182. // CHECK:STDOUT:
  183. // CHECK:STDOUT: fn @Call(%a: %.1, %b: %.7, %c: %.13, %d: %.17) {
  184. // CHECK:STDOUT: !entry:
  185. // CHECK:STDOUT: %a.ref: %.1 = name_ref a, %a
  186. // CHECK:STDOUT: %.loc30_4.1: ref %A = deref %a.ref
  187. // CHECK:STDOUT: %F.ref.loc30: %F.type.1 = name_ref F, @A.%F.decl [template = constants.%F.1]
  188. // CHECK:STDOUT: %.loc30_7: <bound method> = bound_method %.loc30_4.1, %F.ref.loc30
  189. // CHECK:STDOUT: %.loc30_4.2: %.1 = addr_of %.loc30_4.1
  190. // CHECK:STDOUT: %F.call.loc30: init %.2 = call %.loc30_7(%.loc30_4.2)
  191. // CHECK:STDOUT: %b.ref: %.7 = name_ref b, %b
  192. // CHECK:STDOUT: %.loc31_4.1: ref %B = deref %b.ref
  193. // CHECK:STDOUT: %F.ref.loc31: %F.type.2 = name_ref F, @B.%F.decl [template = constants.%F.2]
  194. // CHECK:STDOUT: %.loc31_7: <bound method> = bound_method %.loc31_4.1, %F.ref.loc31
  195. // CHECK:STDOUT: %.loc31_4.2: %.7 = addr_of %.loc31_4.1
  196. // CHECK:STDOUT: %F.call.loc31: init %.2 = call %.loc31_7(%.loc31_4.2)
  197. // CHECK:STDOUT: %c.ref: %.13 = name_ref c, %c
  198. // CHECK:STDOUT: %.loc32_4.1: ref %C = deref %c.ref
  199. // CHECK:STDOUT: %F.ref.loc32: %F.type.3 = name_ref F, @C.%F.decl [template = constants.%F.3]
  200. // CHECK:STDOUT: %.loc32_7: <bound method> = bound_method %.loc32_4.1, %F.ref.loc32
  201. // CHECK:STDOUT: %.loc32_4.2: %.13 = addr_of %.loc32_4.1
  202. // CHECK:STDOUT: %F.call.loc32: init %.2 = call %.loc32_7(%.loc32_4.2)
  203. // CHECK:STDOUT: %d.ref: %.17 = name_ref d, %d
  204. // CHECK:STDOUT: %.loc33_4.1: ref %D = deref %d.ref
  205. // CHECK:STDOUT: %F.ref.loc33: %F.type.2 = name_ref F, @B.%F.decl [template = constants.%F.2]
  206. // CHECK:STDOUT: %.loc33_7: <bound method> = bound_method %.loc33_4.1, %F.ref.loc33
  207. // CHECK:STDOUT: %.loc33_4.2: %.17 = addr_of %.loc33_4.1
  208. // CHECK:STDOUT: %.loc33_9.1: ref %D = deref %.loc33_4.2
  209. // CHECK:STDOUT: %.loc33_9.2: ref %B = class_element_access %.loc33_9.1, element0
  210. // CHECK:STDOUT: %.loc33_9.3: %.7 = addr_of %.loc33_9.2
  211. // CHECK:STDOUT: %.loc33_9.4: %.7 = converted %.loc33_4.2, %.loc33_9.3
  212. // CHECK:STDOUT: %F.call.loc33: init %.2 = call %.loc33_7(%.loc33_9.4)
  213. // CHECK:STDOUT: return
  214. // CHECK:STDOUT: }
  215. // CHECK:STDOUT: