reader/wgsl: Error for unconsumed decorations

When applied to valid module-scope declarations.

Fixed: chromium:1244349
Change-Id: Icb19200cae751ac70974481693ecbcf48fd627f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/63160
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-08-31 18:58:26 +00:00 committed by Tint LUCI CQ
parent 0eaee0cda2
commit 16edcf9b03
2 changed files with 25 additions and 13 deletions

View File

@ -427,27 +427,32 @@ Expect<bool> ParserImpl::expect_global_decl() {
return Failure::kNoMatch;
});
if (decl.errored)
if (decl.errored) {
errored = true;
if (decl.matched)
return true;
}
if (decl.matched) {
return expect_decorations_consumed(decos.value);
}
auto func = function_decl(decos.value);
if (func.errored)
if (func.errored) {
errored = true;
}
if (func.matched) {
builder_.AST().AddFunction(func.value);
return true;
}
if (errored)
if (errored) {
return Failure::kErrored;
}
// Invalid syntax found - try and determine the best error message
// We have decorations parsed, but nothing to consume them?
if (decos.value.size() > 0)
if (decos.value.size() > 0) {
return add_error(next(), "expected declaration after decorations");
}
// We have a statement outside of a function?
auto t = peek();

View File

@ -51,6 +51,13 @@ TEST_F(ParserImplErrorTest, AndInvalidExpr) {
" ^\n");
}
TEST_F(ParserImplErrorTest, AliasDeclInvalidDeco) {
EXPECT("[[block]]type e=u32;",
"test.wgsl:1:3 error: unexpected decorations\n"
"[[block]]type e=u32;\n"
" ^^^^^\n");
}
TEST_F(ParserImplErrorTest, ArrayIndexExprInvalidExpr) {
EXPECT("fn f() { x = y[^]; }",
"test.wgsl:1:16 error: unable to parse expression inside []\n"
@ -275,13 +282,6 @@ TEST_F(ParserImplErrorTest, ForLoopMissingRBrace) {
" ^\n");
}
TEST_F(ParserImplErrorTest, FunctionDeclInvalid) {
EXPECT("[[stage(vertex)]] x;",
"test.wgsl:1:19 error: expected declaration after decorations\n"
"[[stage(vertex)]] x;\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, FunctionDeclDecoMissingEnd) {
EXPECT("[[stage(vertex) fn f() {}",
"test.wgsl:1:17 error: expected ']]' for decoration list\n"
@ -551,6 +551,13 @@ TEST_F(ParserImplErrorTest, GlobalDeclConstExprMissingRParen) {
" ^\n");
}
TEST_F(ParserImplErrorTest, GlobalDeclInvalidDeco) {
EXPECT("[[stage(vertex)]] x;",
"test.wgsl:1:19 error: expected declaration after decorations\n"
"[[stage(vertex)]] x;\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, GlobalDeclSampledTextureMissingLessThan) {
EXPECT("var x : texture_1d;",
"test.wgsl:1:19 error: expected '<' for sampled texture type\n"