mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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:
@@ -10,41 +10,6 @@
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interop/cpp/basics/import/import.carbon
|
||||
|
||||
// ============================================================================
|
||||
// Import C++ namespace indirectly
|
||||
// ============================================================================
|
||||
|
||||
// --- namespace.h
|
||||
|
||||
namespace MyNamespace {
|
||||
|
||||
class MyClass {};
|
||||
|
||||
} // namespace MyNamespace
|
||||
|
||||
// --- namespace_api.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import Cpp library "namespace.h";
|
||||
|
||||
alias MyNamespaceAlias = Cpp.MyNamespace;
|
||||
|
||||
// --- fail_import_namespace_api.carbon
|
||||
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
import library "namespace_api";
|
||||
|
||||
fn F() {
|
||||
// Imports are not implicitly re-exported, so lookup is expected to fail.
|
||||
// CHECK:STDERR: fail_import_namespace_api.carbon:[[@LINE+4]]:17: error: member name `MyClass` not found in `Cpp.MyNamespace` [MemberNameNotFoundInInstScope]
|
||||
// CHECK:STDERR: var unused x: MyNamespaceAlias.MyClass;
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR:
|
||||
var unused x: MyNamespaceAlias.MyClass;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Import C++ struct indirectly
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user