reader/wsgl: Improve error message for missing 'var'

Fixes: tint:295
Change-Id: Id01ad61fa24f14a1d86ca945d941fd27ee1e8f82
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33400
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2020-11-20 11:03:04 +00:00 committed by Commit Bot service account
parent 0f4632d0ae
commit 7f075c2a88
2 changed files with 17 additions and 2 deletions

View File

@ -2577,6 +2577,14 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
auto t = peek();
auto source = t.source();
// tint:295 - Test for `ident COLON` - this is invalid grammar, and without
// special casing will error as "missing = for assignment", which is less
// helpful than this error message:
if (peek(0).IsIdentifier() && peek(1).IsColon()) {
return add_error(peek(0).source(),
"expected 'var' for variable declaration");
}
auto lhs = unary_expression();
if (lhs.errored)
return Failure::kErrored;

View File

@ -70,7 +70,7 @@ TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment) {
TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment2) {
EXPECT("fn f() -> void { a : i32; }",
"test.wgsl:1:20 error: expected '=' for assignment\n"
"test.wgsl:1:18 error: expected 'var' for variable declaration\n"
"fn f() -> void { a : i32; }\n"
" ^\n");
}
@ -216,6 +216,13 @@ TEST_F(ParserImplErrorTest, ForLoopInitializerMissingSemicolon) {
" ^\n");
}
TEST_F(ParserImplErrorTest, ForLoopInitializerMissingVar) {
EXPECT("fn f() -> void { for (i : i32 = 0; i < 8; i=i+1) {} }",
"test.wgsl:1:23 error: expected 'var' for variable declaration\n"
"fn f() -> void { for (i : i32 = 0; i < 8; i=i+1) {} }\n"
" ^\n");
}
TEST_F(ParserImplErrorTest, ForLoopConditionMissingSemicolon) {
EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8 i=i+1) {} }",
"test.wgsl:1:46 error: expected ';' for condition in for loop\n"