mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:30:12 +01:00
Support indirect imports of namespaces. (#7122)
When a namespace that was imported from C++ is indirectly imported, find the corresponding namespace in the current C++ AST and return that instead. This namespace may have completely different contents than the one we found before; that's fine. The current file's view of a namespace depends on what it imported. Assisted-by: Gemini via Antigravity
This commit is contained in:
@@ -3699,11 +3699,24 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
auto name_id = GetLocalNameId(resolver, name_scope.name_id());
|
||||
namespace_decl.name_scope_id =
|
||||
resolver.local_name_scopes().Add(inst_id, name_id, parent_scope_id);
|
||||
auto& local_scope =
|
||||
resolver.local_name_scopes().Get(namespace_decl.name_scope_id);
|
||||
// Namespaces from this package are eagerly imported, so anything we load here
|
||||
// must be a closed import.
|
||||
resolver.local_name_scopes()
|
||||
.Get(namespace_decl.name_scope_id)
|
||||
.set_is_closed_import(true);
|
||||
local_scope.set_is_closed_import(true);
|
||||
|
||||
// If this was a C++ namespace, connect it to the corresponding C++
|
||||
// declaration in this file.
|
||||
if (name_scope.is_cpp_scope()) {
|
||||
if (auto key = FindCorrespondingClangDeclKey(
|
||||
resolver.local_context(), SemIR::LocId(inst_id),
|
||||
resolver.import_ir(), name_scope.clang_decl_context_id())) {
|
||||
auto clang_decl_id = resolver.local_context().clang_decls().Add(
|
||||
{.key = *key, .inst_id = inst_id});
|
||||
local_scope.set_clang_decl_context_id(clang_decl_id, true);
|
||||
}
|
||||
}
|
||||
|
||||
auto namespace_const_id =
|
||||
ReplacePlaceholderImportedInst(resolver, inst_id, namespace_decl);
|
||||
return {.const_id = namespace_const_id};
|
||||
|
||||
Reference in New Issue
Block a user