-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply
is_closed_import
to imported namespaces (#4312)
Spin off from #4294 (comment) --------- Co-authored-by: Richard Smith <[email protected]> Co-authored-by: Carbon Infra Bot <[email protected]>
- Loading branch information
1 parent
7f930d0
commit ff1cc43
Showing
2 changed files
with
134 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// 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 | ||
// TIP: To test this file alone, run: | ||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon | ||
// TIP: To dump output, run: | ||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon | ||
|
||
// --- fn.carbon | ||
|
||
package Other; | ||
namespace Nested; | ||
|
||
// --- fail_conflict.carbon | ||
|
||
import Other; | ||
// CHECK:STDERR: fail_conflict.carbon:[[@LINE+7]]:1: ERROR: Duplicate name being declared in the same scope. | ||
// CHECK:STDERR: namespace Other; | ||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~ | ||
// CHECK:STDERR: fail_conflict.carbon:[[@LINE-4]]:1: Name is previously declared here. | ||
// CHECK:STDERR: import Other; | ||
// CHECK:STDERR: ^~~~~~ | ||
// CHECK:STDERR: | ||
namespace Other; | ||
// CHECK:STDERR: fail_conflict.carbon:[[@LINE+9]]:10: ERROR: Imported packages cannot be used for declarations. | ||
// CHECK:STDERR: fn Other.Nested.F(); | ||
// CHECK:STDERR: ^~~~~~ | ||
// CHECK:STDERR: fail_conflict.carbon:[[@LINE-12]]:1: In import. | ||
// CHECK:STDERR: import Other; | ||
// CHECK:STDERR: ^~~~~~ | ||
// CHECK:STDERR: fn.carbon:3:1: Package imported here. | ||
// CHECK:STDERR: namespace Nested; | ||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~ | ||
fn Other.Nested.F(); | ||
|
||
// CHECK:STDOUT: --- fn.carbon | ||
// CHECK:STDOUT: | ||
// CHECK:STDOUT: imports { | ||
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] { | ||
// CHECK:STDOUT: import Core//prelude | ||
// CHECK:STDOUT: import Core//prelude/operators | ||
// CHECK:STDOUT: import Core//prelude/types | ||
// CHECK:STDOUT: import Core//prelude/operators/arithmetic | ||
// CHECK:STDOUT: import Core//prelude/operators/as | ||
// CHECK:STDOUT: import Core//prelude/operators/bitwise | ||
// CHECK:STDOUT: import Core//prelude/operators/comparison | ||
// CHECK:STDOUT: import Core//prelude/types/bool | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: | ||
// CHECK:STDOUT: file { | ||
// CHECK:STDOUT: package: <namespace> = namespace [template] { | ||
// CHECK:STDOUT: .Core = imports.%Core | ||
// CHECK:STDOUT: .Nested = %Nested | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: %Core.import = import Core | ||
// CHECK:STDOUT: %Nested: <namespace> = namespace [template] {} | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: | ||
// CHECK:STDOUT: --- fail_conflict.carbon | ||
// CHECK:STDOUT: | ||
// CHECK:STDOUT: constants { | ||
// CHECK:STDOUT: %F.type: type = fn_type @F [template] | ||
// CHECK:STDOUT: %.1: type = tuple_type () [template] | ||
// CHECK:STDOUT: %F: %F.type = struct_value () [template] | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: | ||
// CHECK:STDOUT: imports { | ||
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] { | ||
// CHECK:STDOUT: import Core//prelude | ||
// CHECK:STDOUT: import Core//prelude/operators | ||
// CHECK:STDOUT: import Core//prelude/types | ||
// CHECK:STDOUT: import Core//prelude/operators/arithmetic | ||
// CHECK:STDOUT: import Core//prelude/operators/as | ||
// CHECK:STDOUT: import Core//prelude/operators/bitwise | ||
// CHECK:STDOUT: import Core//prelude/operators/comparison | ||
// CHECK:STDOUT: import Core//prelude/types/bool | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: %Other: <namespace> = namespace file.%Other.import, [template] { | ||
// CHECK:STDOUT: .Nested = %Nested | ||
// CHECK:STDOUT: import Other//default | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: %import_ref: <namespace> = import_ref Other//default, inst+3, loaded | ||
// CHECK:STDOUT: %Nested: <namespace> = namespace %import_ref, [template] { | ||
// CHECK:STDOUT: .F = file.%F.decl | ||
// CHECK:STDOUT: import Other//default | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: | ||
// CHECK:STDOUT: file { | ||
// CHECK:STDOUT: package: <namespace> = namespace [template] { | ||
// CHECK:STDOUT: .Core = imports.%Core | ||
// CHECK:STDOUT: .Other = imports.%Other | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: %Core.import = import Core | ||
// CHECK:STDOUT: %Other.import = import Other | ||
// CHECK:STDOUT: %Other: <namespace> = namespace [template] { | ||
// CHECK:STDOUT: .Nested = imports.%Nested | ||
// CHECK:STDOUT: import Other//default | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} | ||
// CHECK:STDOUT: } | ||
// CHECK:STDOUT: | ||
// CHECK:STDOUT: fn @F(); | ||
// CHECK:STDOUT: |