Skip to content

Commit 79c5c47

Browse files
authored
Preserve the is_dynamic property of classes when importing them (#4501)
The test update shows a class derived from an imported base class with a vptr, and without this change the derived class got its own vptr, with this change the derived class can see the base is dynamic, so the derived doesn't need to add a vptr and can rely on the base class's vptr instead.
1 parent 0a6321f commit 79c5c47

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

toolchain/check/import_ref.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,8 @@ class ImportRefResolver {
14181418
class_decl.class_id = context_.classes().Add(
14191419
{GetIncompleteLocalEntityBase(class_decl_id, import_class),
14201420
{.self_type_id = SemIR::TypeId::Invalid,
1421-
.inheritance_kind = import_class.inheritance_kind}});
1421+
.inheritance_kind = import_class.inheritance_kind,
1422+
.is_dynamic = import_class.is_dynamic}});
14221423

14231424
if (import_class.has_parameters()) {
14241425
class_decl.type_id = context_.GetGenericClassType(class_decl.class_id,

toolchain/check/testdata/class/virtual_modifiers.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn F() {
133133
// CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
134134
// CHECK:STDOUT: %.4: type = ptr_type %.2 [template]
135135
// CHECK:STDOUT: %.5: type = unbound_element_type %Derived, %Base [template]
136-
// CHECK:STDOUT: %.6: type = struct_type {.<vptr>: %.1, .base: %Base} [template]
136+
// CHECK:STDOUT: %.6: type = struct_type {.base: %Base} [template]
137137
// CHECK:STDOUT: %.7: <witness> = complete_type_witness %.6 [template]
138138
// CHECK:STDOUT: }
139139
// CHECK:STDOUT:

0 commit comments

Comments
 (0)