From d6fe74b01f5ad983d61c1deeed95dc95221a8f7f Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Mon, 22 Mar 2021 14:55:55 +0000 Subject: [PATCH] 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 Commit-Queue: Antonio Maiorano --- src/validator/validator_function_test.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc index 76aae57c01..e5cc9bcdc8 100644 --- a/src/validator/validator_function_test.cc +++ b/src/validator/validator_function_test.cc @@ -246,5 +246,23 @@ TEST_F(ValidateFunctionTest, FunctionVarInitWithParam) { 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::PipelineStage::kVertex), + }); + + ValidatorImpl& v = Build(); + + EXPECT_TRUE(v.Validate()) << v.error(); +} + } // namespace } // namespace tint