mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-24 01:22:54 +00:00
This revamps the support for cross-package imports, making them look more like a namespace. The planned model is mentioned on [#toolchain](https://discord.com/channels/655572317891461132/655578254970716160/1217586076022210670). This does not implement name lookup into the new namespace structure. A few key changes in this PR (it's a little sprawling) are: - Moves logic for adding package imports from context.* to import.* - Remove SemIR::Import, which was the prior model. This is instead now a SemIR::Namespace with the NameScope getting a new import_ir_scopes field. - Allow SemIR::Namespace to use Parse::ImportDirectiveId in addition to the prior Parse::NamespaceId - The import_ir_scopes field includes a NameScopeId so that as we traverse to child namespaces, we can directly perform name lookup in the other IR. - is_closed_import now tracks whether a namespace comes from a different package. This has a diagnostic implemented in decl_name_stack.
144 lines
4.2 KiB
Plaintext
144 lines
4.2 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
|
|
// --- fail_main.carbon
|
|
|
|
// CHECK:STDERR: fail_main.carbon:[[@LINE+3]]:1: ERROR: Imports from the current package must omit the package name.
|
|
// CHECK:STDERR: import Main;
|
|
// CHECK:STDERR: ^~~~~~
|
|
import Main;
|
|
|
|
// CHECK:STDERR: fail_main.carbon:[[@LINE+3]]:1: ERROR: Imports from the current package must omit the package name.
|
|
// CHECK:STDERR: import Main library "lib";
|
|
// CHECK:STDERR: ^~~~~~
|
|
import Main library "lib";
|
|
|
|
// --- fail_not_main.carbon
|
|
|
|
package NotMain api;
|
|
|
|
// CHECK:STDERR: fail_not_main.carbon:[[@LINE+3]]:1: ERROR: Cannot import `Main` from other packages.
|
|
// CHECK:STDERR: import Main;
|
|
// CHECK:STDERR: ^~~~~~
|
|
import Main;
|
|
|
|
// CHECK:STDERR: fail_not_main.carbon:[[@LINE+3]]:1: ERROR: Cannot import `Main` from other packages.
|
|
// CHECK:STDERR: import Main library "lib";
|
|
// CHECK:STDERR: ^~~~~~
|
|
import Main library "lib";
|
|
|
|
// --- fail_this.carbon
|
|
|
|
package This api;
|
|
|
|
// CHECK:STDERR: fail_this.carbon:[[@LINE+3]]:1: ERROR: File cannot import itself.
|
|
// CHECK:STDERR: import This;
|
|
// CHECK:STDERR: ^~~~~~
|
|
import This;
|
|
|
|
// --- fail_this_lib.carbon
|
|
|
|
package This library "lib" api;
|
|
|
|
// CHECK:STDERR: fail_this_lib.carbon:[[@LINE+3]]:1: ERROR: File cannot import itself.
|
|
// CHECK:STDERR: import library "lib";
|
|
// CHECK:STDERR: ^~~~~~
|
|
import library "lib";
|
|
|
|
// --- implicit_api.carbon
|
|
|
|
package Implicit api;
|
|
|
|
// --- fail_implicit.impl.carbon
|
|
|
|
package Implicit impl;
|
|
|
|
// CHECK:STDERR: fail_implicit.impl.carbon:[[@LINE+3]]:1: ERROR: Explicit import of `api` from `impl` file is redundant with implicit import.
|
|
// CHECK:STDERR: import Implicit;
|
|
// CHECK:STDERR: ^~~~~~
|
|
import Implicit;
|
|
|
|
// --- implicit_lib_api.carbon
|
|
|
|
package Implicit library "lib" api;
|
|
|
|
// --- fail_implicit_lib.impl.carbon
|
|
|
|
package Implicit library "lib" impl;
|
|
|
|
// CHECK:STDERR: fail_implicit_lib.impl.carbon:[[@LINE+3]]:1: ERROR: Explicit import of `api` from `impl` file is redundant with implicit import.
|
|
// CHECK:STDERR: import Implicit library "lib";
|
|
// CHECK:STDERR: ^~~~~~
|
|
import Implicit library "lib";
|
|
|
|
// --- fail_not_found.carbon
|
|
package NotFound api;
|
|
|
|
// CHECK:STDERR: fail_not_found.carbon:[[@LINE+3]]:1: ERROR: Imported API not found.
|
|
// CHECK:STDERR: import ImportNotFound;
|
|
// CHECK:STDERR: ^~~~~~
|
|
import ImportNotFound;
|
|
|
|
// CHECK:STDOUT: --- fail_main.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_not_main.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_this.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_this_lib.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- implicit_api.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_implicit.impl.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- implicit_lib_api.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_implicit_lib.impl.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- fail_not_found.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: .ImportNotFound = %ImportNotFound
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %ImportNotFound: <namespace> = namespace [template] {
|
|
// CHECK:STDOUT: has_error
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|