From b4943bab5035ae350bacbfb586afb5d2b59b4d36 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Mon, 14 Jun 2021 15:29:34 +0000 Subject: [PATCH] Improve function name collision error message Change-Id: Ia1e0460dd0d7b17dab2354311b2989c56143a23f Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54180 Kokoro: Kokoro Reviewed-by: Antonio Maiorano --- src/resolver/function_validation_test.cc | 3 ++- src/resolver/resolver.cc | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/resolver/function_validation_test.cc b/src/resolver/function_validation_test.cc index 11b704ca18..4cbd7ae8ea 100644 --- a/src/resolver/function_validation_test.cc +++ b/src/resolver/function_validation_test.cc @@ -42,7 +42,8 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), - "12:34 error v-0016: function names must be unique 'func'"); + R"(12:34 error v-0016: duplicate function named 'func' +note: first function declared here)"); } TEST_F(ResolverFunctionValidationTest, diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index 539e97ec60..5a4d48e231 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -836,12 +836,15 @@ bool Resolver::ValidateParameter(const VariableInfo* info) { bool Resolver::ValidateFunction(const ast::Function* func, const FunctionInfo* info) { - if (symbol_to_function_.find(func->symbol()) != symbol_to_function_.end()) { + auto func_it = symbol_to_function_.find(func->symbol()); + if (func_it != symbol_to_function_.end()) { diagnostics_.add_error("v-0016", - "function names must be unique '" + + "duplicate function named '" + builder_->Symbols().NameFor(func->symbol()) + "'", func->source()); + diagnostics_.add_note("first function declared here", + func_it->second->declaration->source()); return false; }