| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- // 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
- //
- // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
- //
- // AUTOUPDATE
- // TIP: To test this file alone, run:
- // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/namespace/name_poisoning.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/namespace/name_poisoning.carbon
- // --- no_poison.carbon
- library "[[@TEST_NAME]]";
- namespace N1;
- // `N2.N3` uses `N2.N1` and not `package.N1`.
- namespace N2;
- namespace N2.N1;
- alias N2.N3 = N1;
- class N2.N1.C {}
- class N1.C {}
- fn TestNamespaces() {
- var x: N2.N1.C;
- var y: N2.N3.C* = &x;
- }
- // --- poison.carbon
- library "[[@TEST_NAME]]";
- namespace N1;
- // Use `package.N1` and poison `N2.N1`.
- namespace N2;
- alias N2.N3 = N1;
- // --- fail_declare_after_poison.carbon
- library "[[@TEST_NAME]]";
- namespace N1;
- // Use `package.N1` and poison `N2.N1`.
- namespace N2;
- // CHECK:STDERR: fail_declare_after_poison.carbon:[[@LINE+3]]:15: error: name `N1` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N2.N3 = N1;
- // CHECK:STDERR: ^~
- alias N2.N3 = N1;
- // Failure: N2.N1 declared after it was poisoned.
- // CHECK:STDERR: fail_declare_after_poison.carbon:[[@LINE+4]]:14: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: namespace N2.N1;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- namespace N2.N1;
- // --- fail_use_poison.carbon
- library "[[@TEST_NAME]]";
- namespace N1;
- // Use `package.N1` and poison `N2.N1`.
- namespace N2;
- alias N2.N3 = N1;
- // CHECK:STDERR: fail_use_poison.carbon:[[@LINE+4]]:15: error: member name `N1` not found in `N2` [MemberNameNotFoundInInstScope]
- // CHECK:STDERR: alias N2.N4 = N2.N1;
- // CHECK:STDERR: ^~~~~
- // CHECK:STDERR:
- alias N2.N4 = N2.N1;
- // --- fail_use_declaration_after_poison.carbon
- library "[[@TEST_NAME]]";
- namespace N1;
- // Use `package.N1` and poison `N2.N1`.
- namespace N2;
- // CHECK:STDERR: fail_use_declaration_after_poison.carbon:[[@LINE+3]]:15: error: name `N1` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N2.N3 = N1;
- // CHECK:STDERR: ^~
- alias N2.N3 = N1;
- // Failure: `N2.N1` declared after it was poisoned.
- // CHECK:STDERR: fail_use_declaration_after_poison.carbon:[[@LINE+4]]:14: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: namespace N2.N1;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- namespace N2.N1;
- // CHECK:STDERR: fail_use_declaration_after_poison.carbon:[[@LINE+4]]:15: error: member name `N1` not found in `N2` [MemberNameNotFoundInInstScope]
- // CHECK:STDERR: alias N2.N4 = N2.N1;
- // CHECK:STDERR: ^~~~~
- // CHECK:STDERR:
- alias N2.N4 = N2.N1;
- // --- fail_alias.carbon
- namespace N1;
- namespace N2;
- // CHECK:STDERR: fail_alias.carbon:[[@LINE+7]]:15: error: name `N1` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N2.N1 = N1;
- // CHECK:STDERR: ^~
- // CHECK:STDERR: fail_alias.carbon:[[@LINE+4]]:10: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: alias N2.N1 = N1;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- alias N2.N1 = N1;
- // --- fail_poison_multiple_scopes.carbon
- library "[[@TEST_NAME]]";
- namespace N1;
- namespace N2;
- namespace N2.N3;
- namespace N2.N3.N4;
- // Use `package.N1` and poison:
- // * `N2.N1`
- // * `N2.N3.N1`
- // * `N2.N3.N4.N1`
- // CHECK:STDERR: fail_poison_multiple_scopes.carbon:[[@LINE+3]]:21: error: name `N1` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N2.N3.N4.N5 = N1;
- // CHECK:STDERR: ^~
- alias N2.N3.N4.N5 = N1;
- // CHECK:STDERR: fail_poison_multiple_scopes.carbon:[[@LINE+7]]:20: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: namespace N2.N3.N4.N1;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- // CHECK:STDERR: fail_poison_multiple_scopes.carbon:[[@LINE-6]]:21: error: name `N1` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N2.N3.N4.N5 = N1;
- // CHECK:STDERR: ^~
- namespace N2.N3.N4.N1;
- // CHECK:STDERR: fail_poison_multiple_scopes.carbon:[[@LINE+7]]:17: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: namespace N2.N3.N1;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- // CHECK:STDERR: fail_poison_multiple_scopes.carbon:[[@LINE-14]]:21: error: name `N1` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N2.N3.N4.N5 = N1;
- // CHECK:STDERR: ^~
- namespace N2.N3.N1;
- // CHECK:STDERR: fail_poison_multiple_scopes.carbon:[[@LINE+4]]:14: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: namespace N2.N1;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- namespace N2.N1;
- // --- ignored_poison_in_import.carbon
- library "[[@TEST_NAME]]";
- import library "poison";
- // This doesn't fail.
- namespace N2.N1;
- // --- poison.impl.carbon
- impl library "[[@TEST_NAME]]";
- // TODO: #4622 This should fail since `N2.N1` was poisoned in the api.
- namespace N2.N1;
- // --- fail_poison_when_lookup_fails.carbon
- library "[[@TEST_NAME]]";
- namespace N1;
- // `N1.N3` poisoned when not found.
- // CHECK:STDERR: fail_poison_when_lookup_fails.carbon:[[@LINE+7]]:15: error: name `N3` not found [NameNotFound]
- // CHECK:STDERR: alias N1.N2 = N3;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- // CHECK:STDERR: fail_poison_when_lookup_fails.carbon:[[@LINE+3]]:15: error: name `N3` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N1.N2 = N3;
- // CHECK:STDERR: ^~
- alias N1.N2 = N3;
- // TODO: We should ideally only produce one diagnostic here.
- // CHECK:STDERR: fail_poison_when_lookup_fails.carbon:[[@LINE+7]]:11: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: namespace N3;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- // CHECK:STDERR: fail_poison_when_lookup_fails.carbon:[[@LINE-7]]:15: error: name `N3` used before it was declared [NameUseBeforeDecl]
- // CHECK:STDERR: alias N1.N2 = N3;
- // CHECK:STDERR: ^~
- namespace N3;
- // CHECK:STDERR: fail_poison_when_lookup_fails.carbon:[[@LINE+4]]:14: note: declared here [NameUseBeforeDeclNote]
- // CHECK:STDERR: namespace N1.N3;
- // CHECK:STDERR: ^~
- // CHECK:STDERR:
- namespace N1.N3;
|