Files
carbon-lang/toolchain/check/testdata/packages/fail_conflict_namespace_first.carbon
T
5370041af5 Improve diagnosing of name conflicts in imports. (#3619)
Name conflicts weren't previously tested, and the diagnostics were just
a TODO, so this is also adding testing for that. But handling too.

Removing AddEntry because I think it's hard to make helpful for this
use-case when we want to do a diagnostic followup (because really,
callers want the full `.insert` result of pointer + success), and unused
otherwise.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2024-01-19 16:36:19 +00:00

71 lines
2.1 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
// CHECK:STDERR: namespace_then_fn.carbon: ERROR: Duplicate name being declared in the same scope.
// CHECK:STDERR: namespace_then_fn.carbon: Name is previously declared here.
// --- namespace.carbon
package Example library "namespace" api;
namespace NS;
fn NS.Foo() {}
// --- fn.carbon
package Example library "fn" api;
fn NS() {}
// --- namespace_then_fn.carbon
package Example library "namespace_then_fn" api;
import library "namespace";
import library "fn";
fn NS.Bar() {}
// CHECK:STDOUT: --- namespace.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.NS = %.loc4} [template]
// CHECK:STDOUT: %.loc4: <namespace> = namespace NS, {.Foo = %Foo} [template]
// CHECK:STDOUT: %Foo: <function> = fn_decl @Foo [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Foo() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- fn.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.NS = %NS} [template]
// CHECK:STDOUT: %NS: <function> = fn_decl @NS [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @NS() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- namespace_then_fn.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace package, {.NS = %.2} [template]
// CHECK:STDOUT: %.2: <namespace> = namespace NS, {.Foo = %lazy_import_ref.1, .Bar = %Bar} [template]
// CHECK:STDOUT: %lazy_import_ref.1 = lazy_import_ref ir1, inst+2
// CHECK:STDOUT: %lazy_import_ref.2 = lazy_import_ref ir2, inst+1
// CHECK:STDOUT: %Bar: <function> = fn_decl @Bar [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Bar() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: