C++ interop: Don't crash when looking up names inside an incomplete C++ class/struct/union (#6096)

Only do the lookup when the class is complete.

Before this change we crash in `Sema::LookupQualifiedName()` on
`Declaration context must already be complete!`.
This commit is contained in:
Boaz Brickner
2025-09-18 22:03:42 +00:00
committed by GitHub
parent d137cbe1f1
commit 868c4b768c
5 changed files with 113 additions and 0 deletions
+9
View File
@@ -2143,6 +2143,15 @@ auto ImportNameFromCpp(Context& context, SemIR::LocId loc_id,
builder.Note(loc_id, InCppNameLookup, name_id);
});
if (auto class_decl = context.insts().TryGetAs<SemIR::ClassDecl>(
context.name_scopes().Get(scope_id).inst_id());
class_decl.has_value()) {
if (!context.types().IsComplete(
context.classes().Get(class_decl->class_id).self_type_id)) {
return SemIR::ScopeLookupResult::MakeError();
}
}
auto lookup = ClangLookupName(context, scope_id, name_id);
if (!lookup) {
SemIR::InstId builtin_inst_id =