Validator: add const init with param test

Also test initializing a const from a function parameter.

Bug: tint:642
Change-Id: Ic10a4e8b5a2f67f56bc3720cb59f8d306e175d66
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45520
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2021-03-22 14:55:55 +00:00 committed by Commit Bot service account
parent 4daddd1759
commit d6fe74b01f
1 changed files with 18 additions and 0 deletions

View File

@ -246,5 +246,23 @@ TEST_F(ValidateFunctionTest, FunctionVarInitWithParam) {
EXPECT_TRUE(v.Validate()) << v.error(); EXPECT_TRUE(v.Validate()) << v.error();
} }
TEST_F(ValidateFunctionTest, FunctionConstInitWithParam) {
// fn foo(bar : f32) -> void{
// const baz : f32 = bar;
// }
auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
auto* baz = Const("baz", ty.f32(), Expr("bar"));
Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
ast::DecorationList{
create<ast::StageDecoration>(ast::PipelineStage::kVertex),
});
ValidatorImpl& v = Build();
EXPECT_TRUE(v.Validate()) << v.error();
}
} // namespace } // namespace
} // namespace tint } // namespace tint