[validation] impl v-2000: module-scope variable and function name intersect
bug: tint:260 Change-Id: Ib282b77f475ed3ef4f8096229a41b1bd58342c5a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53121 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
9ef9a10a23
commit
4634c8b736
|
@ -60,7 +60,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
DISABLED_FunctionNameSameAsGlobalVariableName_Fail) {
|
||||
FunctionNameSameAsGlobalVariableName_Fail) {
|
||||
// var foo:f32 = 3.14;
|
||||
// fn foo() -> void {}
|
||||
|
||||
|
@ -78,7 +78,7 @@ TEST_F(ResolverFunctionValidationTest,
|
|||
}
|
||||
|
||||
TEST_F(ResolverFunctionValidationTest,
|
||||
DISABLED_GlobalVariableNameSameAFunctionName_Fail) {
|
||||
GlobalVariableNameSameAFunctionName_Fail) {
|
||||
// fn foo() -> void {}
|
||||
// var<private> foo:f32 = 3.14;
|
||||
|
||||
|
|
|
@ -606,6 +606,20 @@ bool Resolver::GlobalVariable(ast::Variable* var) {
|
|||
}
|
||||
|
||||
bool Resolver::ValidateGlobalVariable(const VariableInfo* info) {
|
||||
auto duplicate_func = symbol_to_function_.find(info->declaration->symbol());
|
||||
if (duplicate_func != symbol_to_function_.end()) {
|
||||
diagnostics_.add_error(
|
||||
"v-2000",
|
||||
"duplicate declaration '" +
|
||||
builder_->Symbols().NameFor(info->declaration->symbol()) + "'",
|
||||
info->declaration->source());
|
||||
diagnostics_.add_note(
|
||||
"'" + builder_->Symbols().NameFor(info->declaration->symbol()) +
|
||||
"' first declared here:",
|
||||
duplicate_func->second->declaration->source());
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto* deco : info->declaration->decorations()) {
|
||||
if (info->declaration->is_const()) {
|
||||
if (auto* override_deco = deco->As<ast::OverrideDecoration>()) {
|
||||
|
@ -812,6 +826,22 @@ bool Resolver::ValidateFunction(const ast::Function* func,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool is_global = false;
|
||||
VariableInfo* var;
|
||||
if (variable_stack_.get(func->symbol(), &var, &is_global)) {
|
||||
if (is_global) {
|
||||
diagnostics_.add_error("v-2000",
|
||||
"duplicate declaration '" +
|
||||
builder_->Symbols().NameFor(func->symbol()) +
|
||||
"'",
|
||||
func->source());
|
||||
diagnostics_.add_note("'" + builder_->Symbols().NameFor(func->symbol()) +
|
||||
"' first declared here:",
|
||||
var->declaration->source());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto stage_deco_count = 0;
|
||||
auto workgroup_deco_count = 0;
|
||||
for (auto* deco : func->decorations()) {
|
||||
|
|
Loading…
Reference in New Issue