Explicitly mark as unsupported instead of crashing mapping a parameter record type defined not in a namespace (#5777)

Before this change we crash in this case when trying to use the outer
type.
After this change we diagnose a TODO.
Will add the missing support for this in a separate PR.

Part of #5533.
This commit is contained in:
Boaz Brickner
2025-07-18 02:42:45 +00:00
committed by GitHub
parent 61290fdee9
commit f4f521de7f
4 changed files with 268 additions and 2 deletions
+11 -2
View File
@@ -700,8 +700,17 @@ static auto MapRecordType(Context& context, SemIR::LocId loc_id,
// Check if the declaration is already mapped.
SemIR::InstId record_inst_id = LookupClangDeclInstId(context, record_decl);
if (!record_inst_id.has_value()) {
auto parent_inst_id =
AsCarbonNamespace(context, record_decl->getDeclContext());
clang::DeclContext* decl_context = record_decl->getDeclContext();
if (!clang::isa<clang::TranslationUnitDecl>(decl_context) &&
!clang::isa<clang::NamespaceDecl>(decl_context)) {
context.TODO(loc_id,
"Unsupported mapping of a C++ record to a type within a "
"declaration context that is not the translation unit or "
"a namespace");
return {.inst_id = SemIR::ErrorInst::TypeInstId,
.type_id = SemIR::ErrorInst::TypeId};
}
auto parent_inst_id = AsCarbonNamespace(context, decl_context);
auto parent_name_scope_id =
context.insts().GetAs<SemIR::Namespace>(parent_inst_id).name_scope_id;
SemIR::NameId record_name_id =