Improve function name collision error message

Change-Id: Ia1e0460dd0d7b17dab2354311b2989c56143a23f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54180
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-06-14 15:29:34 +00:00
parent cd49e0e074
commit b4943bab50
2 changed files with 7 additions and 3 deletions

View File

@ -42,7 +42,8 @@ TEST_F(ResolverFunctionValidationTest, FunctionNamesMustBeUnique_fail) {
EXPECT_FALSE(r()->Resolve()); EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), 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, TEST_F(ResolverFunctionValidationTest,

View File

@ -836,12 +836,15 @@ bool Resolver::ValidateParameter(const VariableInfo* info) {
bool Resolver::ValidateFunction(const ast::Function* func, bool Resolver::ValidateFunction(const ast::Function* func,
const FunctionInfo* info) { 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", diagnostics_.add_error("v-0016",
"function names must be unique '" + "duplicate function named '" +
builder_->Symbols().NameFor(func->symbol()) + builder_->Symbols().NameFor(func->symbol()) +
"'", "'",
func->source()); func->source());
diagnostics_.add_note("first function declared here",
func_it->second->declaration->source());
return false; return false;
} }