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:
parent
0f4632d0ae
commit
7f075c2a88
|
@ -2577,6 +2577,14 @@ Maybe<ast::AssignmentStatement*> ParserImpl::assignment_stmt() {
|
||||||
auto t = peek();
|
auto t = peek();
|
||||||
auto source = t.source();
|
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();
|
auto lhs = unary_expression();
|
||||||
if (lhs.errored)
|
if (lhs.errored)
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
|
|
|
@ -70,9 +70,9 @@ TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment) {
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment2) {
|
TEST_F(ParserImplErrorTest, AssignmentStmtMissingAssignment2) {
|
||||||
EXPECT("fn f() -> void { a : i32; }",
|
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"
|
"fn f() -> void { a : i32; }\n"
|
||||||
" ^\n");
|
" ^\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplErrorTest, AssignmentStmtMissingSemicolon) {
|
TEST_F(ParserImplErrorTest, AssignmentStmtMissingSemicolon) {
|
||||||
|
@ -216,6 +216,13 @@ TEST_F(ParserImplErrorTest, ForLoopInitializerMissingSemicolon) {
|
||||||
" ^\n");
|
" ^\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) {
|
TEST_F(ParserImplErrorTest, ForLoopConditionMissingSemicolon) {
|
||||||
EXPECT("fn f() -> void { for (var i : i32 = 0; i < 8 i=i+1) {} }",
|
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"
|
"test.wgsl:1:46 error: expected ';' for condition in for loop\n"
|
||||||
|
|
Loading…
Reference in New Issue