Clarify what specific name in the Core package is looked for when diagnosing that the Core package is not found (#4571)

I believe this makes the error easier to understand.
This commit is contained in:
Boaz Brickner
2024-11-22 15:48:18 +00:00
committed by GitHub
parent d870e0bd7c
commit bbd8b55be2
12 changed files with 19 additions and 17 deletions
+7 -5
View File
@@ -608,7 +608,7 @@ auto Context::LookupQualifiedName(SemIRLoc loc, SemIR::NameId name_id,
//
// TODO: Consider tracking the Core package in SemIR so we don't need to use
// name lookup to find it.
static auto GetCorePackage(Context& context, SemIRLoc loc)
static auto GetCorePackage(Context& context, SemIRLoc loc, llvm::StringRef name)
-> SemIR::NameScopeId {
auto core_ident_id = context.identifiers().Add("Core");
auto packaging = context.parse_tree().packaging_decl();
@@ -630,15 +630,17 @@ static auto GetCorePackage(Context& context, SemIRLoc loc)
}
}
CARBON_DIAGNOSTIC(CoreNotFound, Error,
"package `Core` implicitly referenced here, but not found");
context.emitter().Emit(loc, CoreNotFound);
CARBON_DIAGNOSTIC(
CoreNotFound, Error,
"`Core.{0}` implicitly referenced here, but package `Core` not found",
std::string);
context.emitter().Emit(loc, CoreNotFound, name.str());
return SemIR::NameScopeId::Invalid;
}
auto Context::LookupNameInCore(SemIRLoc loc, llvm::StringRef name)
-> SemIR::InstId {
auto core_package_id = GetCorePackage(*this, loc);
auto core_package_id = GetCorePackage(*this, loc, name);
if (!core_package_id.is_valid()) {
return SemIR::InstId::BuiltinErrorInst;
}