[validation] v-2000: Add disabled test for module-scope variable and function
name intersect v-2000: Function names must not have any intersect with module-scope variable names. A declaration must not introduce a name when that identifier is already in scope with the same end scope as another instance of that name. A module-scope variable and a function have the same end scope ie. end of the program. bug: tint:260 Change-Id: I95321d3e6c04b0344c3acfb7b77cb483b3659728 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/52820 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@chromium.org> Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com> Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
edb644c821
commit
3a472bc5c2
|
@ -59,6 +59,79 @@ TEST_F(ResolverFunctionValidationTest,
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverFunctionValidationTest,
|
||||||
|
DISABLED_FunctionNameSameAsGlobalVariableName_Fail) {
|
||||||
|
// var foo:f32 = 3.14;
|
||||||
|
// fn foo() -> void {}
|
||||||
|
|
||||||
|
auto* global_var = Var(Source{Source::Location{56, 78}}, "foo", ty.f32(),
|
||||||
|
ast::StorageClass::kPrivate, Expr(3.14f));
|
||||||
|
AST().AddGlobalVariable(global_var);
|
||||||
|
|
||||||
|
Func(Source{Source::Location{12, 34}}, "foo", ast::VariableList{}, ty.void_(),
|
||||||
|
ast::StatementList{}, ast::DecorationList{});
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve()) << r()->error();
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error v-2000: duplicate declaration 'foo'\n56:78 note: "
|
||||||
|
"'foo' first declared here:");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverFunctionValidationTest,
|
||||||
|
DISABLED_GlobalVariableNameSameAFunctionName_Fail) {
|
||||||
|
// fn foo() -> void {}
|
||||||
|
// var<private> foo:f32 = 3.14;
|
||||||
|
|
||||||
|
Func(Source{Source::Location{12, 34}}, "foo", ast::VariableList{}, ty.void_(),
|
||||||
|
ast::StatementList{}, ast::DecorationList{});
|
||||||
|
auto* global_var =
|
||||||
|
Var("foo", ty.f32(), ast::StorageClass::kPrivate, Expr(3.14f));
|
||||||
|
AST().AddGlobalVariable(global_var);
|
||||||
|
|
||||||
|
EXPECT_FALSE(r()->Resolve()) << r()->error();
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"error v-2000: duplicate declaration 'foo'\n12:34 note: 'foo' "
|
||||||
|
"first declared here:");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverFunctionValidationTest, FunctionUsingSameVariableName_Pass) {
|
||||||
|
// fn func() -> i32 {
|
||||||
|
// var func:i32 = 0;
|
||||||
|
// return func;
|
||||||
|
// }
|
||||||
|
|
||||||
|
auto* var = Var("func", ty.i32(), ast::StorageClass::kNone, Expr(0));
|
||||||
|
Func("func", ast::VariableList{}, ty.i32(),
|
||||||
|
ast::StatementList{
|
||||||
|
Decl(var),
|
||||||
|
Return(Source{Source::Location{12, 34}}, Expr("func")),
|
||||||
|
},
|
||||||
|
ast::DecorationList{});
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ResolverFunctionValidationTest,
|
||||||
|
FunctionNameSameAsFunctionScopeVariableName_Pass) {
|
||||||
|
// fn a() -> void { var b:i32 = 0; }
|
||||||
|
// fn b() -> i32 { return 2; }
|
||||||
|
|
||||||
|
auto* var = Var("b", ty.i32(), ast::StorageClass::kNone, Expr(0));
|
||||||
|
Func("a", ast::VariableList{}, ty.void_(),
|
||||||
|
ast::StatementList{
|
||||||
|
Decl(var),
|
||||||
|
},
|
||||||
|
ast::DecorationList{});
|
||||||
|
|
||||||
|
Func(Source{Source::Location{12, 34}}, "b", ast::VariableList{}, ty.i32(),
|
||||||
|
ast::StatementList{
|
||||||
|
Return(2),
|
||||||
|
},
|
||||||
|
ast::DecorationList{});
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
|
TEST_F(ResolverFunctionValidationTest, FunctionEndWithoutReturnStatement_Fail) {
|
||||||
// fn func -> int { var a:i32 = 2; }
|
// fn func -> int { var a:i32 = 2; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue