virtual_modifiers.carbon 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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/virtual_modifiers.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/virtual_modifiers.carbon
  10. // --- modifiers.carbon
  11. package Modifiers;
  12. base class Base {
  13. virtual fn H();
  14. impl fn I();
  15. }
  16. abstract class Abstract {
  17. abstract fn J();
  18. virtual fn K();
  19. impl fn L();
  20. }
  21. // --- todo_fail_later_base.carbon
  22. package FailLaterBase;
  23. import Modifiers;
  24. base class Derived {
  25. virtual fn F();
  26. extend base: Modifiers.Base;
  27. }
  28. // --- init.carbon
  29. package Init;
  30. import Modifiers;
  31. fn F() {
  32. var v: Modifiers.Base = {};
  33. }
  34. // CHECK:STDOUT: --- modifiers.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  38. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  39. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  40. // CHECK:STDOUT: %I.type: type = fn_type @I [template]
  41. // CHECK:STDOUT: %I: %I.type = struct_value () [template]
  42. // CHECK:STDOUT: %.1: type = ptr_type <vtable> [template]
  43. // CHECK:STDOUT: %.2: type = struct_type {.<vptr>: %.1} [template]
  44. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  45. // CHECK:STDOUT: %Abstract: type = class_type @Abstract [template]
  46. // CHECK:STDOUT: %J.type: type = fn_type @J [template]
  47. // CHECK:STDOUT: %J: %J.type = struct_value () [template]
  48. // CHECK:STDOUT: %K.type: type = fn_type @K [template]
  49. // CHECK:STDOUT: %K: %K.type = struct_value () [template]
  50. // CHECK:STDOUT: %L.type: type = fn_type @L [template]
  51. // CHECK:STDOUT: %L: %L.type = struct_value () [template]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  56. // CHECK:STDOUT: import Core//prelude
  57. // CHECK:STDOUT: import Core//prelude/...
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: file {
  62. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  63. // CHECK:STDOUT: .Core = imports.%Core
  64. // CHECK:STDOUT: .Base = %Base.decl
  65. // CHECK:STDOUT: .Abstract = %Abstract.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.import = import Core
  68. // CHECK:STDOUT: %Base.decl: type = class_decl @Base [template = constants.%Base] {} {}
  69. // CHECK:STDOUT: %Abstract.decl: type = class_decl @Abstract [template = constants.%Abstract] {} {}
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: class @Base {
  73. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  74. // CHECK:STDOUT: %I.decl: %I.type = fn_decl @I [template = constants.%I] {} {}
  75. // CHECK:STDOUT: %.loc8: <witness> = complete_type_witness %.2 [template = constants.%.3]
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%Base
  79. // CHECK:STDOUT: .H = %H.decl
  80. // CHECK:STDOUT: .I = %I.decl
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: class @Abstract {
  84. // CHECK:STDOUT: %J.decl: %J.type = fn_decl @J [template = constants.%J] {} {}
  85. // CHECK:STDOUT: %K.decl: %K.type = fn_decl @K [template = constants.%K] {} {}
  86. // CHECK:STDOUT: %L.decl: %L.type = fn_decl @L [template = constants.%L] {} {}
  87. // CHECK:STDOUT: %.loc16: <witness> = complete_type_witness %.2 [template = constants.%.3]
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: !members:
  90. // CHECK:STDOUT: .Self = constants.%Abstract
  91. // CHECK:STDOUT: .J = %J.decl
  92. // CHECK:STDOUT: .K = %K.decl
  93. // CHECK:STDOUT: .L = %L.decl
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: virtual fn @H();
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: impl fn @I();
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: abstract fn @J();
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: virtual fn @K();
  103. // CHECK:STDOUT:
  104. // CHECK:STDOUT: impl fn @L();
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: --- todo_fail_later_base.carbon
  107. // CHECK:STDOUT:
  108. // CHECK:STDOUT: constants {
  109. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  110. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  111. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  112. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  113. // CHECK:STDOUT: %.5: type = unbound_element_type %Derived, %Base [template]
  114. // CHECK:STDOUT: %.6: type = struct_type {.base: %Base} [template]
  115. // CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT:
  118. // CHECK:STDOUT: imports {
  119. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  120. // CHECK:STDOUT: import Core//prelude
  121. // CHECK:STDOUT: import Core//prelude/...
  122. // CHECK:STDOUT: }
  123. // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
  124. // CHECK:STDOUT: .Base = %import_ref.1
  125. // CHECK:STDOUT: import Modifiers//default
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
  128. // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
  129. // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
  130. // CHECK:STDOUT: %import_ref.4 = import_ref Modifiers//default, inst+9, unloaded
  131. // CHECK:STDOUT: }
  132. // CHECK:STDOUT:
  133. // CHECK:STDOUT: file {
  134. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  135. // CHECK:STDOUT: .Core = imports.%Core
  136. // CHECK:STDOUT: .Modifiers = imports.%Modifiers
  137. // CHECK:STDOUT: .Derived = %Derived.decl
  138. // CHECK:STDOUT: }
  139. // CHECK:STDOUT: %Core.import = import Core
  140. // CHECK:STDOUT: %Modifiers.import = import Modifiers
  141. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {} {}
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT:
  144. // CHECK:STDOUT: class @Derived {
  145. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  146. // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
  147. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
  148. // CHECK:STDOUT: %.loc8: %.5 = base_decl %Base, element0 [template]
  149. // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.6 [template = constants.%.7]
  150. // CHECK:STDOUT:
  151. // CHECK:STDOUT: !members:
  152. // CHECK:STDOUT: .Self = constants.%Derived
  153. // CHECK:STDOUT: .F = %F.decl
  154. // CHECK:STDOUT: .base = %.loc8
  155. // CHECK:STDOUT: extend %Base.ref
  156. // CHECK:STDOUT: }
  157. // CHECK:STDOUT:
  158. // CHECK:STDOUT: class @Base {
  159. // CHECK:STDOUT: !members:
  160. // CHECK:STDOUT: .Self = imports.%import_ref.2
  161. // CHECK:STDOUT: .H = imports.%import_ref.3
  162. // CHECK:STDOUT: .I = imports.%import_ref.4
  163. // CHECK:STDOUT: }
  164. // CHECK:STDOUT:
  165. // CHECK:STDOUT: virtual fn @F();
  166. // CHECK:STDOUT:
  167. // CHECK:STDOUT: --- init.carbon
  168. // CHECK:STDOUT:
  169. // CHECK:STDOUT: constants {
  170. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  171. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  172. // CHECK:STDOUT: %Base: type = class_type @Base [template]
  173. // CHECK:STDOUT: %.5: type = struct_type {} [template]
  174. // CHECK:STDOUT: }
  175. // CHECK:STDOUT:
  176. // CHECK:STDOUT: imports {
  177. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  178. // CHECK:STDOUT: import Core//prelude
  179. // CHECK:STDOUT: import Core//prelude/...
  180. // CHECK:STDOUT: }
  181. // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
  182. // CHECK:STDOUT: .Base = %import_ref.1
  183. // CHECK:STDOUT: import Modifiers//default
  184. // CHECK:STDOUT: }
  185. // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
  186. // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
  187. // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
  188. // CHECK:STDOUT: %import_ref.4 = import_ref Modifiers//default, inst+9, unloaded
  189. // CHECK:STDOUT: }
  190. // CHECK:STDOUT:
  191. // CHECK:STDOUT: file {
  192. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  193. // CHECK:STDOUT: .Core = imports.%Core
  194. // CHECK:STDOUT: .Modifiers = imports.%Modifiers
  195. // CHECK:STDOUT: .F = %F.decl
  196. // CHECK:STDOUT: }
  197. // CHECK:STDOUT: %Core.import = import Core
  198. // CHECK:STDOUT: %Modifiers.import = import Modifiers
  199. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  200. // CHECK:STDOUT: }
  201. // CHECK:STDOUT:
  202. // CHECK:STDOUT: class @Base {
  203. // CHECK:STDOUT: !members:
  204. // CHECK:STDOUT: .Self = imports.%import_ref.2
  205. // CHECK:STDOUT: .H = imports.%import_ref.3
  206. // CHECK:STDOUT: .I = imports.%import_ref.4
  207. // CHECK:STDOUT: }
  208. // CHECK:STDOUT:
  209. // CHECK:STDOUT: fn @F() {
  210. // CHECK:STDOUT: !entry:
  211. // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
  212. // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
  213. // CHECK:STDOUT: %v.var: ref %Base = var v
  214. // CHECK:STDOUT: %v: ref %Base = bind_name v, %v.var
  215. // CHECK:STDOUT: %.loc7_28.1: %.5 = struct_literal ()
  216. // CHECK:STDOUT: %.loc7_28.2: init %Base = class_init (<error>), %v.var [template = <error>]
  217. // CHECK:STDOUT: %.loc7_29: init %Base = converted %.loc7_28.1, %.loc7_28.2 [template = <error>]
  218. // CHECK:STDOUT: assign %v.var, %.loc7_29
  219. // CHECK:STDOUT: return
  220. // CHECK:STDOUT: }
  221. // CHECK:STDOUT: