Require imported C++ types to be complete before creating a Core.Copy witness (#7106)

Fixes a crash that would occur due to `scope_id` of the class being
unset.
This commit is contained in:
David Blaikie
2026-04-23 17:54:21 +00:00
committed by GitHub
parent 8205c8e460
commit 8e32faba18
3 changed files with 41 additions and 0 deletions
+12
View File
@@ -15,6 +15,7 @@
#include "toolchain/check/import_ref.h"
#include "toolchain/check/inst.h"
#include "toolchain/check/type.h"
#include "toolchain/check/type_completion.h"
#include "toolchain/sem_ir/builtin_function_kind.h"
#include "toolchain/sem_ir/ids.h"
#include "toolchain/sem_ir/typed_insts.h"
@@ -113,6 +114,17 @@ static auto BuildCopyWitness(
return SemIR::InstId::None;
}
if (auto* class_decl = dyn_cast<clang::CXXRecordDecl>(tag_decl)) {
auto class_type_id = SemIR::TypeId::ForTypeConstant(query_self_const_id);
if (!Check::RequireCompleteType(
context, class_type_id, SemIR::LocId::None, [&](auto& builder) {
CARBON_DIAGNOSTIC(IncompleteTypeInCopyWitness, Context,
"argument to C++ call has incomplete type {0}",
SemIR::TypeId);
builder.Context(loc_id, IncompleteTypeInCopyWitness,
class_type_id);
})) {
return SemIR::ErrorInst::InstId;
}
auto decl_info = DeclInfo{.decl = clang_sema.LookupCopyingConstructor(
class_decl, clang::Qualifiers::Const),
.signature = {.num_params = 1}};