diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index ced1d3e0c965..89b229040d7a 100644 --- a/toolchain/check/import_ref.cpp +++ b/toolchain/check/import_ref.cpp @@ -892,7 +892,8 @@ static auto GetLocalConstantId(ImportRefResolver& resolver, return SemIR::ConstantId::None; } auto import_decl_inst_id = resolver.import_generics().Get(generic_id).decl_id; - auto import_decl_inst = resolver.import_insts().Get(import_decl_inst_id); + auto import_decl_inst = + resolver.import_insts().GetWithAttachedType(import_decl_inst_id); if (import_decl_inst.Is()) { // For an impl declaration, the imported entity can be found via the // declaration. @@ -1370,6 +1371,8 @@ static auto AddAssociatedEntities(ImportContext& context, import_name_id = context.import_entity_names().Get(import_ref->entity_name_id).name_id; } else { + // We don't need `GetWithAttachedType` here because we don't access the + // type. CARBON_FATAL("Unhandled associated entity kind: {0}", context.import_insts().Get(inst_id).kind()); } @@ -1399,6 +1402,10 @@ static auto RetryOrDone(ImportRefResolver& resolver, SemIR::ConstantId const_id) // that there is no new work. static auto ResolveAsUntyped(ImportContext& context, SemIR::Inst inst) -> ResolveResult { + // AddImportedConstant produces an unattached constant, so its type must + // be unattached as well. + inst.SetType( + context.local_context().types().GetUnattachedType(inst.type_id())); auto result = AddImportedConstant(context.local_context(), inst); CARBON_CHECK(result.is_constant(), "{0} is not constant", inst); return ResolveResult::Done(result); @@ -2854,7 +2861,7 @@ static auto TryResolveInstCanonical(ImportRefResolver& resolver, return ResolveResult::Done(resolver.local_constant_values().Get(inst_id)); } - auto untyped_inst = resolver.import_insts().Get(inst_id); + auto untyped_inst = resolver.import_insts().GetWithAttachedType(inst_id); CARBON_KIND_SWITCH(untyped_inst) { case CARBON_KIND(SemIR::AdaptDecl inst): { return TryResolveTypedInst(resolver, inst, inst_id); diff --git a/toolchain/check/testdata/class/generic/adapt.carbon b/toolchain/check/testdata/class/generic/adapt.carbon index 36ed22857a93..7039d2a7ad35 100644 --- a/toolchain/check/testdata/class/generic/adapt.carbon +++ b/toolchain/check/testdata/class/generic/adapt.carbon @@ -301,7 +301,7 @@ fn ImportedConvertLocal(a: Adapter(C)) -> i32 { // CHECK:STDOUT: %Main.import_ref.709: = import_ref Main//adapt_specific_type, loc10_1, loaded [concrete = constants.%complete_type.c07] // CHECK:STDOUT: %Main.import_ref.feb = import_ref Main//adapt_specific_type, inst42 [no loc], unloaded // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic] -// CHECK:STDOUT: %.22b: %C.elem.66c = field_decl x, element0 [concrete] +// CHECK:STDOUT: %.22b: @C.%C.elem (%C.elem.66c) = field_decl x, element0 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { @@ -670,7 +670,7 @@ fn ImportedConvertLocal(a: Adapter(C)) -> i32 { // CHECK:STDOUT: %Main.import_ref.feb = import_ref Main//extend_adapt_specific_type_library, inst42 [no loc], unloaded // CHECK:STDOUT: %Main.import_ref.19d12e.2: type = import_ref Main//extend_adapt_specific_type_library, loc12_21, loaded [concrete = constants.%C.239] // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic] -// CHECK:STDOUT: %.22b: %C.elem.66c = field_decl x, element0 [concrete] +// CHECK:STDOUT: %.22b: @C.%C.elem (%C.elem.66c) = field_decl x, element0 [concrete] // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/operators/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic] // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/class/generic/base_is_generic.carbon b/toolchain/check/testdata/class/generic/base_is_generic.carbon index 412a98dcc9ba..0e1b09f3e415 100644 --- a/toolchain/check/testdata/class/generic/base_is_generic.carbon +++ b/toolchain/check/testdata/class/generic/base_is_generic.carbon @@ -295,7 +295,7 @@ fn H() { // CHECK:STDOUT: %Main.import_ref.d24 = import_ref Main//extend_generic_base, loc13_27, unloaded // CHECK:STDOUT: %Main.import_ref.77a301.2: type = import_ref Main//extend_generic_base, loc13_26, loaded [concrete = constants.%Base.7a8] // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic] -// CHECK:STDOUT: %.e66: %Base.elem.9af = field_decl x, element0 [concrete] +// CHECK:STDOUT: %.e66: @Base.%Base.elem (%Base.elem.9af) = field_decl x, element0 [concrete] // CHECK:STDOUT: %.be7: %Param.elem = field_decl y, element0 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: diff --git a/toolchain/check/testdata/class/generic/import.carbon b/toolchain/check/testdata/class/generic/import.carbon index 1d983c39755a..5164c0692a83 100644 --- a/toolchain/check/testdata/class/generic/import.carbon +++ b/toolchain/check/testdata/class/generic/import.carbon @@ -490,7 +490,7 @@ class Class(U:! type) { // CHECK:STDOUT: %Main.import_ref.e76: @CompleteClass.%CompleteClass.elem (%CompleteClass.elem.28a) = import_ref Main//foo, loc7_8, loaded [concrete = %.364] // CHECK:STDOUT: %Main.import_ref.a52: @CompleteClass.%F.type (%F.type.14f) = import_ref Main//foo, loc8_17, loaded [symbolic = @CompleteClass.%F (constants.%F.874)] // CHECK:STDOUT: %Main.import_ref.5ab3ec.2: type = import_ref Main//foo, loc6_21, loaded [symbolic = @CompleteClass.%T (constants.%T)] -// CHECK:STDOUT: %.364: %CompleteClass.elem.28a = field_decl n, element0 [concrete] +// CHECK:STDOUT: %.364: @CompleteClass.%CompleteClass.elem (%CompleteClass.elem.28a) = field_decl n, element0 [concrete] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file {