From dd7c64bad04bf8d2a6d8584608a704c4eea79a59 Mon Sep 17 00:00:00 2001 From: Boaz Brickner Date: Fri, 14 Feb 2025 11:21:50 -0800 Subject: [PATCH] When diagnosing a duplicate name, point to the name instead of the instruction (#4953) Left TODOs where more work is necessary before this change can be applied or its impact can be verified. Includes #4952, to avoid regression in some cases. Similar to #4938. See https://discord.com/channels/655572317891461132/655578254970716160/1339007384361762857. --- toolchain/check/decl_name_stack.cpp | 2 +- toolchain/check/handle_binding_pattern.cpp | 2 +- toolchain/check/handle_class.cpp | 2 +- toolchain/check/handle_function.cpp | 9 +++++---- toolchain/check/handle_interface.cpp | 2 +- toolchain/check/handle_namespace.cpp | 4 ++-- toolchain/check/import.cpp | 4 ++++ toolchain/check/import_ref.cpp | 1 + toolchain/check/name_lookup.cpp | 2 ++ .../testdata/class/no_prelude/implicit_import.carbon | 4 ++-- .../definition/no_prelude/implicit_import.carbon | 4 ++-- toolchain/check/testdata/generic/local.carbon | 4 ++-- .../fail_todo_define_default_fn_out_of_line.carbon | 8 ++++---- .../no_prelude/fail_definition_imported.carbon | 4 ++-- .../interface/no_prelude/fail_duplicate.carbon | 8 ++++---- .../no_prelude/fail_redeclare_member.carbon | 4 ++-- .../no_prelude/fail_todo_generic_default_fn.carbon | 4 ++-- .../interface/no_prelude/syntactic_merge.carbon | 12 ++++++------ .../interop/cpp/no_prelude/cpp_namespace.carbon | 4 ++-- .../namespace/fail_conflict_after_merge.carbon | 8 ++++---- .../fail_conflict_imported_namespace_first.carbon | 4 ++-- .../fail_conflict_imported_namespace_nested.carbon | 4 ++-- .../fail_conflict_imported_namespace_second.carbon | 4 ++-- .../packages/no_prelude/cross_package_import.carbon | 4 ++-- 24 files changed, 58 insertions(+), 50 deletions(-) diff --git a/toolchain/check/decl_name_stack.cpp b/toolchain/check/decl_name_stack.cpp index f2fdf59b367b..cf5b4bedb2a0 100644 --- a/toolchain/check/decl_name_stack.cpp +++ b/toolchain/check/decl_name_stack.cpp @@ -180,7 +180,7 @@ auto DeclNameStack::AddNameOrDiagnose(NameContext name_context, DiagnosePoisonedName(*context_, name_context.poisoning_loc_id, name_context.loc_id); } else if (auto id = name_context.prev_inst_id(); id.has_value()) { - DiagnoseDuplicateName(*context_, target_id, id); + DiagnoseDuplicateName(*context_, name_context.loc_id, id); } else { AddName(name_context, target_id, access_kind); } diff --git a/toolchain/check/handle_binding_pattern.cpp b/toolchain/check/handle_binding_pattern.cpp index 827856bf4daa..77014076b7db 100644 --- a/toolchain/check/handle_binding_pattern.cpp +++ b/toolchain/check/handle_binding_pattern.cpp @@ -78,7 +78,7 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id, context.scope_stack().PushCompileTimeBinding(bind_id); } auto name_context = - context.decl_name_stack().MakeUnqualifiedName(node_id, name_id); + context.decl_name_stack().MakeUnqualifiedName(name_node, name_id); context.decl_name_stack().AddNameOrDiagnose( name_context, bind_id, introducer.modifier_set.GetAccessKind()); context.full_pattern_stack().AddBindName(name_id); diff --git a/toolchain/check/handle_class.cpp b/toolchain/check/handle_class.cpp index 69f2eb6f8aa1..9728dbf07133 100644 --- a/toolchain/check/handle_class.cpp +++ b/toolchain/check/handle_class.cpp @@ -163,7 +163,7 @@ static auto MergeOrAddName(Context& context, Parse::AnyClassDeclId node_id, if (!prev_class_id.has_value()) { // This is a redeclaration of something other than a class. - DiagnoseDuplicateName(context, class_decl_id, prev_id); + DiagnoseDuplicateName(context, name_context.loc_id, prev_id); return; } diff --git a/toolchain/check/handle_function.cpp b/toolchain/check/handle_function.cpp index 8a1ff874212b..a0df7396e90c 100644 --- a/toolchain/check/handle_function.cpp +++ b/toolchain/check/handle_function.cpp @@ -138,7 +138,7 @@ static auto MergeFunctionRedecl(Context& context, // Check whether this is a redeclaration, merging if needed. static auto TryMergeRedecl(Context& context, Parse::AnyFunctionDeclId node_id, - SemIR::InstId prev_id, + SemIR::InstId prev_id, SemIR::LocId name_loc_id, SemIR::FunctionDecl& function_decl, SemIR::Function& function_info, bool is_definition) -> void { @@ -179,7 +179,7 @@ static auto TryMergeRedecl(Context& context, Parse::AnyFunctionDeclId node_id, } if (!prev_function_id.has_value()) { - DiagnoseDuplicateName(context, function_info.latest_decl_id(), prev_id); + DiagnoseDuplicateName(context, name_loc_id, prev_id); return; } @@ -295,8 +295,9 @@ static auto BuildFunctionDecl(Context& context, DiagnosePoisonedName(context, name_context.poisoning_loc_id, name_context.loc_id); } else { - TryMergeRedecl(context, node_id, name_context.prev_inst_id(), function_decl, - function_info, is_definition); + TryMergeRedecl(context, node_id, name_context.prev_inst_id(), + name_context.loc_id, function_decl, function_info, + is_definition); } // Create a new function if this isn't a valid redeclaration. diff --git a/toolchain/check/handle_interface.cpp b/toolchain/check/handle_interface.cpp index 19cf5a893664..b105eb3f5c6c 100644 --- a/toolchain/check/handle_interface.cpp +++ b/toolchain/check/handle_interface.cpp @@ -104,7 +104,7 @@ static auto BuildInterfaceDecl(Context& context, } } else { // This is a redeclaration of something other than a interface. - DiagnoseDuplicateName(context, interface_decl_id, existing_id); + DiagnoseDuplicateName(context, name_context.loc_id, existing_id); } } diff --git a/toolchain/check/handle_namespace.cpp b/toolchain/check/handle_namespace.cpp index 2e7b3df199f8..6883321178a1 100644 --- a/toolchain/check/handle_namespace.cpp +++ b/toolchain/check/handle_namespace.cpp @@ -64,7 +64,7 @@ auto HandleParseNode(Context& context, Parse::NamespaceId node_id) -> bool { .Get(existing->name_scope_id) .is_closed_import()) { // The existing name is a package name, so this is a name conflict. - DiagnoseDuplicateName(context, namespace_id, existing_inst_id); + DiagnoseDuplicateName(context, name_context.loc_id, existing_inst_id); // Treat this as a local namespace name from now on to avoid further // diagnostics. @@ -78,7 +78,7 @@ auto HandleParseNode(Context& context, Parse::NamespaceId node_id) -> bool { context.SetNamespaceNodeId(existing_inst_id, node_id); } } else { - DiagnoseDuplicateName(context, namespace_id, existing_inst_id); + DiagnoseDuplicateName(context, name_context.loc_id, existing_inst_id); } } diff --git a/toolchain/check/import.cpp b/toolchain/check/import.cpp index fc8b8cf6211e..2bfaae86be85 100644 --- a/toolchain/check/import.cpp +++ b/toolchain/check/import.cpp @@ -107,6 +107,8 @@ auto AddImportNamespace(Context& context, SemIR::TypeId namespace_type_id, if (diagnose_duplicate_namespace) { auto import_id = make_import_id(); CARBON_CHECK(import_id.has_value()); + // TODO: Pass the import package name location instead of the import + // id to get more accurate location. DiagnoseDuplicateName(context, import_id, prev_inst_id); } return {.name_scope_id = namespace_inst->name_scope_id, @@ -148,6 +150,8 @@ auto AddImportNamespace(Context& context, SemIR::TypeId namespace_type_id, // may be overwriting a poisoned entry here. auto& result = parent_scope->GetEntry(entry_id).result; if (!result.is_poisoned() && !inserted) { + // TODO: Pass the import namespace name location instead of the namespace id + // to get more accurate location. DiagnoseDuplicateName(context, namespace_id, result.target_inst_id()); } result = SemIR::ScopeLookupResult::MakeFound(namespace_id, diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index aeed0dff9635..e7db4fabe14d 100644 --- a/toolchain/check/import_ref.cpp +++ b/toolchain/check/import_ref.cpp @@ -149,6 +149,7 @@ auto VerifySameCanonicalImportIRInst(Context& context, SemIR::InstId prev_id, } auto conflict_id = AddImportRef(context, {.ir_id = new_ir_id, .inst_id = new_inst_id}); + // TODO: Pass the imported name location instead of the conflict id. DiagnoseDuplicateName(context, conflict_id, prev_id); } diff --git a/toolchain/check/name_lookup.cpp b/toolchain/check/name_lookup.cpp index d06b50784b41..6d42f2c74799 100644 --- a/toolchain/check/name_lookup.cpp +++ b/toolchain/check/name_lookup.cpp @@ -17,6 +17,8 @@ auto AddNameToLookup(Context& context, SemIR::NameId name_id, if (auto existing = context.scope_stack().LookupOrAddName(name_id, target_id, scope_index); existing.has_value()) { + // TODO: Add coverage to this use case and use the location of the name + // instead of the target. DiagnoseDuplicateName(context, target_id, existing); } } diff --git a/toolchain/check/testdata/class/no_prelude/implicit_import.carbon b/toolchain/check/testdata/class/no_prelude/implicit_import.carbon index ec67910d989c..fe6b2244f629 100644 --- a/toolchain/check/testdata/class/no_prelude/implicit_import.carbon +++ b/toolchain/check/testdata/class/no_prelude/implicit_import.carbon @@ -71,9 +71,9 @@ alias B = C; impl library "[[@TEST_NAME]]"; -// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:7: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: class B {} -// CHECK:STDERR: ^~~~~~~~~ +// CHECK:STDERR: ^ // CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE-5]]:6: in import [InImport] // CHECK:STDERR: def_alias.carbon:5:7: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: alias B = C; diff --git a/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon b/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon index dcce0537be68..2d2ba6ca6321 100644 --- a/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon +++ b/toolchain/check/testdata/function/definition/no_prelude/implicit_import.carbon @@ -111,9 +111,9 @@ alias B = A; impl library "[[@TEST_NAME]]"; -// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn B() {} -// CHECK:STDERR: ^~~~~~~~ +// CHECK:STDERR: ^ // CHECK:STDERR: fail_def_alias.impl.carbon:[[@LINE-5]]:6: in import [InImport] // CHECK:STDERR: def_alias.carbon:5:7: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: alias B = A; diff --git a/toolchain/check/testdata/generic/local.carbon b/toolchain/check/testdata/generic/local.carbon index 2d8b25a79092..859e4cfb4e0c 100644 --- a/toolchain/check/testdata/generic/local.carbon +++ b/toolchain/check/testdata/generic/local.carbon @@ -25,9 +25,9 @@ library "[[@TEST_NAME]]"; fn F() { // TODO: Decide on what behavior we want here. We don't reject the corresponding case outside of a function. - // CHECK:STDERR: fail_param_shadows_class.carbon:[[@LINE+7]]:3: error: duplicate name being declared in the same scope [NameDeclDuplicate] + // CHECK:STDERR: fail_param_shadows_class.carbon:[[@LINE+7]]:9: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: class C(C:! type) { - // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~ + // CHECK:STDERR: ^ // CHECK:STDERR: fail_param_shadows_class.carbon:[[@LINE+4]]:11: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: class C(C:! type) { // CHECK:STDERR: ^ diff --git a/toolchain/check/testdata/interface/fail_todo_define_default_fn_out_of_line.carbon b/toolchain/check/testdata/interface/fail_todo_define_default_fn_out_of_line.carbon index b04f2f2a53f5..a97c0a83cc06 100644 --- a/toolchain/check/testdata/interface/fail_todo_define_default_fn_out_of_line.carbon +++ b/toolchain/check/testdata/interface/fail_todo_define_default_fn_out_of_line.carbon @@ -24,18 +24,18 @@ interface Interface { default fn G(a: i32, b: i32) -> i32; } -// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:14: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn Interface.F() {} -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^ // CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE-12]]:3: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: default fn F(); // CHECK:STDERR: ^~~~~~~~~~~~~~~ // CHECK:STDERR: fn Interface.F() {} -// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE+7]]:14: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn Interface.G(a: i32, b: i32) -> i32 = "int.sadd"; -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^ // CHECK:STDERR: fail_todo_define_default_fn_out_of_line.carbon:[[@LINE-15]]:3: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: default fn G(a: i32, b: i32) -> i32; // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/toolchain/check/testdata/interface/no_prelude/fail_definition_imported.carbon b/toolchain/check/testdata/interface/no_prelude/fail_definition_imported.carbon index 7d0cf3ddc7bb..7a6402fbd9a3 100644 --- a/toolchain/check/testdata/interface/no_prelude/fail_definition_imported.carbon +++ b/toolchain/check/testdata/interface/no_prelude/fail_definition_imported.carbon @@ -19,9 +19,9 @@ interface I; library "[[@TEST_NAME]]"; import library "a"; -// CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_b.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: interface I {} -// CHECK:STDERR: ^~~~~~~~~~~~~ +// CHECK:STDERR: ^ // CHECK:STDERR: fail_b.carbon:[[@LINE-5]]:1: in import [InImport] // CHECK:STDERR: a.carbon:4:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: interface I; diff --git a/toolchain/check/testdata/interface/no_prelude/fail_duplicate.carbon b/toolchain/check/testdata/interface/no_prelude/fail_duplicate.carbon index 644b51e65df5..13ea37cb6f3c 100644 --- a/toolchain/check/testdata/interface/no_prelude/fail_duplicate.carbon +++ b/toolchain/check/testdata/interface/no_prelude/fail_duplicate.carbon @@ -48,9 +48,9 @@ library "[[@TEST_NAME]]"; fn Function(); -// CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: interface Function; -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~~~~~~ // CHECK:STDERR: fail_name_conflict_with_fn.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: fn Function(); // CHECK:STDERR: ^~~~~~~~~~~~~~ @@ -61,9 +61,9 @@ interface Function; class Class; -// CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: interface Class { } -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~~~ // CHECK:STDERR: fail_name_conflict_with_class.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: class Class; // CHECK:STDERR: ^~~~~~~~~~~~ diff --git a/toolchain/check/testdata/interface/no_prelude/fail_redeclare_member.carbon b/toolchain/check/testdata/interface/no_prelude/fail_redeclare_member.carbon index 3d975d99213a..96536f957912 100644 --- a/toolchain/check/testdata/interface/no_prelude/fail_redeclare_member.carbon +++ b/toolchain/check/testdata/interface/no_prelude/fail_redeclare_member.carbon @@ -10,9 +10,9 @@ interface Interface { fn F(); - // CHECK:STDERR: fail_redeclare_member.carbon:[[@LINE+7]]:3: error: duplicate name being declared in the same scope [NameDeclDuplicate] + // CHECK:STDERR: fail_redeclare_member.carbon:[[@LINE+7]]:6: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn F(); - // CHECK:STDERR: ^~~~~~~ + // CHECK:STDERR: ^ // CHECK:STDERR: fail_redeclare_member.carbon:[[@LINE-4]]:3: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: fn F(); // CHECK:STDERR: ^~~~~~~ diff --git a/toolchain/check/testdata/interface/no_prelude/fail_todo_generic_default_fn.carbon b/toolchain/check/testdata/interface/no_prelude/fail_todo_generic_default_fn.carbon index fb61bf546fde..537dad3a29da 100644 --- a/toolchain/check/testdata/interface/no_prelude/fail_todo_generic_default_fn.carbon +++ b/toolchain/check/testdata/interface/no_prelude/fail_todo_generic_default_fn.carbon @@ -13,9 +13,9 @@ interface I(T:! type) { fn F[self: Self]() -> Self; } -// CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE+7]]:16: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn I(T:! type).F[self: Self]() -> Self { return self; } -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^ // CHECK:STDERR: fail_todo_generic_default_fn.carbon:[[@LINE-6]]:3: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: fn F[self: Self]() -> Self; // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/toolchain/check/testdata/interface/no_prelude/syntactic_merge.carbon b/toolchain/check/testdata/interface/no_prelude/syntactic_merge.carbon index 54612dfdb0bf..f1536daa1a79 100644 --- a/toolchain/check/testdata/interface/no_prelude/syntactic_merge.carbon +++ b/toolchain/check/testdata/interface/no_prelude/syntactic_merge.carbon @@ -69,18 +69,18 @@ interface Bar(a:! D); impl library "[[@TEST_NAME]]"; -// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: interface Foo(a:! C) {} -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~ // CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE-5]]:6: in import [InImport] // CHECK:STDERR: two_file.carbon:7:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: interface Foo(a:! C); // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~ // CHECK:STDERR: interface Foo(a:! C) {} -// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: interface Bar(a:! D) {} -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~ // CHECK:STDERR: fail_todo_two_file.impl.carbon:[[@LINE-14]]:6: in import [InImport] // CHECK:STDERR: two_file.carbon:8:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: interface Bar(a:! D); @@ -156,9 +156,9 @@ alias D = C; // TODO: This fails because importing interfaces doesn't work well. It should // fail due to `C` versus `D`, but may succeed if importing interfaces is fixed // before syntax matching on imports is supported. -// CHECK:STDERR: fail_alias_two_file.impl.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_alias_two_file.impl.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: interface Foo(a:! D) {} -// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~ // CHECK:STDERR: fail_alias_two_file.impl.carbon:[[@LINE-10]]:6: in import [InImport] // CHECK:STDERR: alias_two_file.carbon:6:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: interface Foo(a:! C); diff --git a/toolchain/check/testdata/interop/cpp/no_prelude/cpp_namespace.carbon b/toolchain/check/testdata/interop/cpp/no_prelude/cpp_namespace.carbon index c5b1547a29ae..5d6ffa28e873 100644 --- a/toolchain/check/testdata/interop/cpp/no_prelude/cpp_namespace.carbon +++ b/toolchain/check/testdata/interop/cpp/no_prelude/cpp_namespace.carbon @@ -16,9 +16,9 @@ library "[[@TEST_NAME]]"; import Cpp library "header.h"; -// CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: namespace Cpp; -// CHECK:STDERR: ^~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~ // CHECK:STDERR: fail_duplicate_cpp_name.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: import Cpp library "header.h"; // CHECK:STDERR: ^~~~~~ diff --git a/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon b/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon index 61111c403f3c..c3183b0677bf 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_after_merge.carbon @@ -24,9 +24,9 @@ import library "namespace"; // imported declaration. namespace NS; -// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn NS(); -// CHECK:STDERR: ^~~~~~~~ +// CHECK:STDERR: ^~ // CHECK:STDERR: fail_conflict.carbon:[[@LINE-9]]:1: in import [InImport] // CHECK:STDERR: namespace.carbon:4:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: namespace NS; @@ -38,9 +38,9 @@ fn NS(); // we don't move it. namespace NS; -// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn NS(); -// CHECK:STDERR: ^~~~~~~~ +// CHECK:STDERR: ^~ // CHECK:STDERR: fail_conflict.carbon:[[@LINE-23]]:1: in import [InImport] // CHECK:STDERR: namespace.carbon:4:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: namespace NS; diff --git a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon index 88eb3b4646d9..1db6042aa15d 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_first.carbon @@ -20,9 +20,9 @@ package Example; import library "namespace"; -// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:4: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn NS(); -// CHECK:STDERR: ^~~~~~~~ +// CHECK:STDERR: ^~ // CHECK:STDERR: fail_conflict.carbon:[[@LINE-5]]:1: in import [InImport] // CHECK:STDERR: namespace.carbon:4:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: namespace NS; diff --git a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon index bc243a546851..d3e5c9948e34 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_nested.carbon @@ -16,9 +16,9 @@ namespace Nested; // --- fail_conflict.carbon import Other; -// CHECK:STDERR: fail_conflict.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_conflict.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: namespace Other; -// CHECK:STDERR: ^~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~~~ // CHECK:STDERR: fail_conflict.carbon:[[@LINE-4]]:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: import Other; // CHECK:STDERR: ^~~~~~ diff --git a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon index 7b54f14a0f78..9bacb68a9a69 100644 --- a/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon +++ b/toolchain/check/testdata/namespace/fail_conflict_imported_namespace_second.carbon @@ -20,9 +20,9 @@ package Example; import library "fn"; -// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: namespace NS; -// CHECK:STDERR: ^~~~~~~~~~~~~ +// CHECK:STDERR: ^~ // CHECK:STDERR: fail_conflict.carbon:[[@LINE-5]]:1: in import [InImport] // CHECK:STDERR: fn.carbon:4:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: fn NS(); diff --git a/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon b/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon index 2eb5fe321c09..0a5276b0302a 100644 --- a/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon +++ b/toolchain/check/testdata/packages/no_prelude/cross_package_import.carbon @@ -150,9 +150,9 @@ library "[[@TEST_NAME]]"; import Other library "other_fn"; -// CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE+7]]:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] +// CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE+7]]:11: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: namespace Other; -// CHECK:STDERR: ^~~~~~~~~~~~~~~~ +// CHECK:STDERR: ^~~~~ // CHECK:STDERR: fail_main_reopen_other.carbon:[[@LINE-5]]:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: import Other library "other_fn"; // CHECK:STDERR: ^~~~~~