mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Handling for cross-package imports of "export name". (#3967)
Starts warning on duplicate "export name" because I'm updating name lookup to make it work. Need to think harder about how to handle cross-package "export import". But adding some failing tests to sketch out what *should* work.
This commit is contained in:
@@ -38,6 +38,20 @@ auto HandleExportDecl(Context& context, Parse::ExportDeclId node_id) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto inst = context.insts().Get(inst_id);
|
||||
|
||||
if (inst.Is<SemIR::ExportDecl>()) {
|
||||
CARBON_DIAGNOSTIC(ExportRedundant, Warning,
|
||||
"`export` matches previous `export`.");
|
||||
CARBON_DIAGNOSTIC(ExportPrevious, Note, "Previous `export` here.");
|
||||
context.emitter()
|
||||
.Build(node_id, ExportRedundant)
|
||||
// Use the location of the export itself, not the exported instruction.
|
||||
.Note(context.insts().GetLocId(inst_id), ExportPrevious)
|
||||
.Emit();
|
||||
return true;
|
||||
}
|
||||
|
||||
auto import_ref = context.insts().TryGetAs<SemIR::ImportRefLoaded>(inst_id);
|
||||
if (!import_ref) {
|
||||
CARBON_DIAGNOSTIC(ExportNotImportedEntity, Error,
|
||||
@@ -57,6 +71,14 @@ auto HandleExportDecl(Context& context, Parse::ExportDeclId node_id) -> bool {
|
||||
.value_id = inst_id}});
|
||||
context.AddExport(export_id);
|
||||
|
||||
// Replace the ImportRef in name lookup, both for the above duplicate
|
||||
// diagnostic and so that cross-package imports can find it easily.
|
||||
auto bind_name = context.bind_names().Get(import_ref->bind_name_id);
|
||||
auto& names = context.name_scopes().Get(bind_name.enclosing_scope_id).names;
|
||||
auto it = names.find(bind_name.name_id);
|
||||
CARBON_CHECK(it->second == inst_id);
|
||||
it->second = export_id;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user