88// TIP: To dump output, run:
99// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/virtual_modifiers.carbon
1010
11+ // --- modifiers.carbon
12+
13+ package Modifiers;
1114
1215base class Base {
1316 virtual fn H ();
@@ -23,7 +26,32 @@ abstract class Abstract {
2326 impl fn L ();
2427}
2528
26- // CHECK:STDOUT: --- virtual_modifiers.carbon
29+ // --- todo_fail_later_base.carbon
30+
31+ package FailLaterBase;
32+
33+ import Modifiers ;
34+
35+ base class Derived {
36+ virtual fn F ();
37+ extend base: Modifiers.Base;
38+ }
39+
40+ // --- fail_todo_init.carbon
41+
42+ package Init;
43+
44+ import Modifiers ;
45+
46+ fn F () {
47+ // TODO: The vptr shouldn't be counted for programmer-facing behavior.
48+ // CHECK:STDERR: fail_todo_init.carbon:[[@LINE+3]]:27: error: cannot initialize class with 1 field(s) from struct with 0 field(s).
49+ // CHECK:STDERR: var v: Modifiers.Base = {};
50+ // CHECK:STDERR: ^~
51+ var v: Modifiers.Base = {};
52+ }
53+
54+ // CHECK:STDOUT: --- modifiers.carbon
2755// CHECK:STDOUT:
2856// CHECK:STDOUT: constants {
2957// CHECK:STDOUT: %Base: type = class_type @Base [template]
@@ -32,8 +60,9 @@ abstract class Abstract {
3260// CHECK:STDOUT: %H: %H.type = struct_value () [template]
3361// CHECK:STDOUT: %I.type: type = fn_type @I [template]
3462// CHECK:STDOUT: %I: %I.type = struct_value () [template]
35- // CHECK:STDOUT: %.2: type = struct_type {} [template]
36- // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
63+ // CHECK:STDOUT: %.2: type = ptr_type <vtable> [template]
64+ // CHECK:STDOUT: %.3: type = struct_type {.<vptr>: %.2} [template]
65+ // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
3766// CHECK:STDOUT: %Abstract: type = class_type @Abstract [template]
3867// CHECK:STDOUT: %J.type: type = fn_type @J [template]
3968// CHECK:STDOUT: %J: %J.type = struct_value () [template]
@@ -70,7 +99,7 @@ abstract class Abstract {
7099// CHECK:STDOUT: class @Base {
71100// CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
72101// CHECK:STDOUT: %I.decl: %I.type = fn_decl @I [template = constants.%I] {} {}
73- // CHECK:STDOUT: %.loc16 : <witness> = complete_type_witness %.2 [template = constants.%.3 ]
102+ // CHECK:STDOUT: %.loc8 : <witness> = complete_type_witness %.3 [template = constants.%.4 ]
74103// CHECK:STDOUT:
75104// CHECK:STDOUT: !members:
76105// CHECK:STDOUT: .Self = constants.%Base
@@ -82,7 +111,7 @@ abstract class Abstract {
82111// CHECK:STDOUT: %J.decl: %J.type = fn_decl @J [template = constants.%J] {} {}
83112// CHECK:STDOUT: %K.decl: %K.type = fn_decl @K [template = constants.%K] {} {}
84113// CHECK:STDOUT: %L.decl: %L.type = fn_decl @L [template = constants.%L] {} {}
85- // CHECK:STDOUT: %.loc24 : <witness> = complete_type_witness %.2 [template = constants.%.3 ]
114+ // CHECK:STDOUT: %.loc16 : <witness> = complete_type_witness %.3 [template = constants.%.4 ]
86115// CHECK:STDOUT:
87116// CHECK:STDOUT: !members:
88117// CHECK:STDOUT: .Self = constants.%Abstract
@@ -101,3 +130,139 @@ abstract class Abstract {
101130// CHECK:STDOUT:
102131// CHECK:STDOUT: impl fn @L();
103132// CHECK:STDOUT:
133+ // CHECK:STDOUT: --- todo_fail_later_base.carbon
134+ // CHECK:STDOUT:
135+ // CHECK:STDOUT: constants {
136+ // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
137+ // CHECK:STDOUT: %F.type: type = fn_type @F [template]
138+ // CHECK:STDOUT: %.1: type = tuple_type () [template]
139+ // CHECK:STDOUT: %F: %F.type = struct_value () [template]
140+ // CHECK:STDOUT: %Base: type = class_type @Base [template]
141+ // CHECK:STDOUT: %.2: type = ptr_type <vtable> [template]
142+ // CHECK:STDOUT: %.3: type = struct_type {.<vptr>: %.2} [template]
143+ // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
144+ // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
145+ // CHECK:STDOUT: %.6: type = unbound_element_type %Derived, %Base [template]
146+ // CHECK:STDOUT: %.7: type = struct_type {.<vptr>: %.2, .base: %Base} [template]
147+ // CHECK:STDOUT: %.8: <witness> = complete_type_witness %.7 [template]
148+ // CHECK:STDOUT: }
149+ // CHECK:STDOUT:
150+ // CHECK:STDOUT: imports {
151+ // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
152+ // CHECK:STDOUT: import Core//prelude
153+ // CHECK:STDOUT: import Core//prelude/operators
154+ // CHECK:STDOUT: import Core//prelude/types
155+ // CHECK:STDOUT: import Core//prelude/operators/arithmetic
156+ // CHECK:STDOUT: import Core//prelude/operators/as
157+ // CHECK:STDOUT: import Core//prelude/operators/bitwise
158+ // CHECK:STDOUT: import Core//prelude/operators/comparison
159+ // CHECK:STDOUT: import Core//prelude/types/bool
160+ // CHECK:STDOUT: }
161+ // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
162+ // CHECK:STDOUT: .Base = %import_ref.1
163+ // CHECK:STDOUT: import Modifiers//default
164+ // CHECK:STDOUT: }
165+ // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
166+ // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
167+ // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
168+ // CHECK:STDOUT: %import_ref.4 = import_ref Modifiers//default, inst+9, unloaded
169+ // CHECK:STDOUT: }
170+ // CHECK:STDOUT:
171+ // CHECK:STDOUT: file {
172+ // CHECK:STDOUT: package: <namespace> = namespace [template] {
173+ // CHECK:STDOUT: .Core = imports.%Core
174+ // CHECK:STDOUT: .Modifiers = imports.%Modifiers
175+ // CHECK:STDOUT: .Derived = %Derived.decl
176+ // CHECK:STDOUT: }
177+ // CHECK:STDOUT: %Core.import = import Core
178+ // CHECK:STDOUT: %Modifiers.import = import Modifiers
179+ // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {} {}
180+ // CHECK:STDOUT: }
181+ // CHECK:STDOUT:
182+ // CHECK:STDOUT: class @Derived {
183+ // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
184+ // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
185+ // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
186+ // CHECK:STDOUT: %.loc8: %.6 = base_decl %Base, element0 [template]
187+ // CHECK:STDOUT: %.loc9: <witness> = complete_type_witness %.7 [template = constants.%.8]
188+ // CHECK:STDOUT:
189+ // CHECK:STDOUT: !members:
190+ // CHECK:STDOUT: .Self = constants.%Derived
191+ // CHECK:STDOUT: .F = %F.decl
192+ // CHECK:STDOUT: .base = %.loc8
193+ // CHECK:STDOUT: extend name_scope4
194+ // CHECK:STDOUT: }
195+ // CHECK:STDOUT:
196+ // CHECK:STDOUT: class @Base {
197+ // CHECK:STDOUT: !members:
198+ // CHECK:STDOUT: .Self = imports.%import_ref.2
199+ // CHECK:STDOUT: .H = imports.%import_ref.3
200+ // CHECK:STDOUT: .I = imports.%import_ref.4
201+ // CHECK:STDOUT: }
202+ // CHECK:STDOUT:
203+ // CHECK:STDOUT: virtual fn @F();
204+ // CHECK:STDOUT:
205+ // CHECK:STDOUT: --- fail_todo_init.carbon
206+ // CHECK:STDOUT:
207+ // CHECK:STDOUT: constants {
208+ // CHECK:STDOUT: %F.type: type = fn_type @F [template]
209+ // CHECK:STDOUT: %.1: type = tuple_type () [template]
210+ // CHECK:STDOUT: %F: %F.type = struct_value () [template]
211+ // CHECK:STDOUT: %Base: type = class_type @Base [template]
212+ // CHECK:STDOUT: %.2: type = ptr_type <vtable> [template]
213+ // CHECK:STDOUT: %.3: type = struct_type {.<vptr>: %.2} [template]
214+ // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
215+ // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
216+ // CHECK:STDOUT: %.6: type = struct_type {} [template]
217+ // CHECK:STDOUT: }
218+ // CHECK:STDOUT:
219+ // CHECK:STDOUT: imports {
220+ // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
221+ // CHECK:STDOUT: import Core//prelude
222+ // CHECK:STDOUT: import Core//prelude/operators
223+ // CHECK:STDOUT: import Core//prelude/types
224+ // CHECK:STDOUT: import Core//prelude/operators/arithmetic
225+ // CHECK:STDOUT: import Core//prelude/operators/as
226+ // CHECK:STDOUT: import Core//prelude/operators/bitwise
227+ // CHECK:STDOUT: import Core//prelude/operators/comparison
228+ // CHECK:STDOUT: import Core//prelude/types/bool
229+ // CHECK:STDOUT: }
230+ // CHECK:STDOUT: %Modifiers: <namespace> = namespace file.%Modifiers.import, [template] {
231+ // CHECK:STDOUT: .Base = %import_ref.1
232+ // CHECK:STDOUT: import Modifiers//default
233+ // CHECK:STDOUT: }
234+ // CHECK:STDOUT: %import_ref.1: type = import_ref Modifiers//default, inst+3, loaded [template = constants.%Base]
235+ // CHECK:STDOUT: %import_ref.2 = import_ref Modifiers//default, inst+4, unloaded
236+ // CHECK:STDOUT: %import_ref.3 = import_ref Modifiers//default, inst+5, unloaded
237+ // CHECK:STDOUT: %import_ref.4 = import_ref Modifiers//default, inst+9, unloaded
238+ // CHECK:STDOUT: }
239+ // CHECK:STDOUT:
240+ // CHECK:STDOUT: file {
241+ // CHECK:STDOUT: package: <namespace> = namespace [template] {
242+ // CHECK:STDOUT: .Core = imports.%Core
243+ // CHECK:STDOUT: .Modifiers = imports.%Modifiers
244+ // CHECK:STDOUT: .F = %F.decl
245+ // CHECK:STDOUT: }
246+ // CHECK:STDOUT: %Core.import = import Core
247+ // CHECK:STDOUT: %Modifiers.import = import Modifiers
248+ // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
249+ // CHECK:STDOUT: }
250+ // CHECK:STDOUT:
251+ // CHECK:STDOUT: class @Base {
252+ // CHECK:STDOUT: !members:
253+ // CHECK:STDOUT: .Self = imports.%import_ref.2
254+ // CHECK:STDOUT: .H = imports.%import_ref.3
255+ // CHECK:STDOUT: .I = imports.%import_ref.4
256+ // CHECK:STDOUT: }
257+ // CHECK:STDOUT:
258+ // CHECK:STDOUT: fn @F() {
259+ // CHECK:STDOUT: !entry:
260+ // CHECK:STDOUT: %Modifiers.ref: <namespace> = name_ref Modifiers, imports.%Modifiers [template = imports.%Modifiers]
261+ // CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
262+ // CHECK:STDOUT: %v.var: ref %Base = var v
263+ // CHECK:STDOUT: %v: ref %Base = bind_name v, %v.var
264+ // CHECK:STDOUT: %.loc11: %.6 = struct_literal ()
265+ // CHECK:STDOUT: assign %v.var, <error>
266+ // CHECK:STDOUT: return
267+ // CHECK:STDOUT: }
268+ // CHECK:STDOUT:
0 commit comments