Gracefully handle member access on a runtime type value (#7744)

Avoid CHECK failure when performing member access on a runtime type
value. We will just fail to find the CanonicalFacetOrTypeValue and then
fail lookup.
This commit is contained in:
Dana Jansens
2026-09-09 23:05:48 +00:00
committed by GitHub
parent 431e349757
commit 2aeecef17a
2 changed files with 34 additions and 3 deletions
+26
View File
@@ -129,6 +129,32 @@ fn F(T: Z) {
T.G();
}
// --- fail_member_access_runtime_facet.carbon
library "[[@TEST_NAME]]";
interface Z {
fn G();
}
fn F(T: Z) {
// CHECK:STDERR: fail_member_access_runtime_facet.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Z` in type `Z` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: T.G();
// CHECK:STDERR: ^~~
// CHECK:STDERR:
T.G();
}
// --- fail_member_access_runtime_type.carbon
library "[[@TEST_NAME]]";
fn F(T: type) {
// CHECK:STDERR: fail_member_access_runtime_type.carbon:[[@LINE+4]]:3: error: type `type` does not support qualified expressions [QualifiedExprUnsupported]
// CHECK:STDERR: T.G();
// CHECK:STDERR: ^~~
// CHECK:STDERR:
T.G();
}
// CHECK:STDOUT: --- facet_value_copy_from_reference.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
+8 -3
View File
@@ -304,10 +304,15 @@ auto GetCanonicalFacetOrTypeValue(Context& context, SemIR::ConstantId const_id)
auto TryGetCanonicalFacetValue(Context& context, SemIR::InstId inst_id)
-> SemIR::InstId {
if (context.insts().Get(inst_id).type_id() == SemIR::TypeType::TypeId) {
return GetCanonicalFacetOrTypeValue(context, inst_id);
if (context.insts().Get(inst_id).type_id() != SemIR::TypeType::TypeId) {
return SemIR::InstId::None;
}
return SemIR::InstId::None;
auto const_id = context.constant_values().Get(inst_id);
if (!const_id.is_constant()) {
return SemIR::InstId::None;
}
return context.constant_values().GetInstId(
GetCanonicalFacetOrTypeValue(context, const_id));
}
} // namespace Carbon::Check