diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 3d2c8e3d69..7318b37c3a 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1023,13 +1023,15 @@ Maybe ParserImpl::type_decl() { return Failure::kErrored; auto type = type_decl(decos.value); - if (type.errored) + if (type.errored) { return Failure::kErrored; - if (!type.matched) + } + if (!expect_decorations_consumed(decos.value)) { + return Failure::kErrored; + } + if (!type.matched) { return Failure::kNoMatch; - - if (!expect_decorations_consumed(decos.value)) - return Failure::kErrored; + } return type; } diff --git a/src/reader/wgsl/parser_impl_error_msg_test.cc b/src/reader/wgsl/parser_impl_error_msg_test.cc index 5f6fbb9170..83013a207f 100644 --- a/src/reader/wgsl/parser_impl_error_msg_test.cc +++ b/src/reader/wgsl/parser_impl_error_msg_test.cc @@ -422,6 +422,13 @@ TEST_F(ParserImplErrorTest, FunctionDeclMissingRBrace) { " ^\n"); } +TEST_F(ParserImplErrorTest, FunctionScopeUnusedDecl) { + EXPECT("fn f(a:i32)->i32{return a;[[size(1)]]}", + "test.wgsl:1:29 error: unexpected decorations\n" + "fn f(a:i32)->i32{return a;[[size(1)]]}\n" + " ^^^^\n"); +} + TEST_F(ParserImplErrorTest, FunctionMissingOpenLine) { EXPECT(R"(let bar : vec2 = vec2(1., 2.); var a : f32 = bar[0];