Improve error message when suffixing float with f
Fixes: tint:277 Change-Id: I7ec3bb758c7d80c95c6ecd51eebf4144b696bec5 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33668 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
7e4ffa0064
commit
fecf10664a
|
@ -2622,6 +2622,11 @@ Maybe<ast::Literal*> ParserImpl::const_literal() {
|
|||
return create<ast::UintLiteral>(type, t.to_u32());
|
||||
}
|
||||
if (match(Token::Type::kFloatLiteral)) {
|
||||
auto p = peek();
|
||||
if (p.IsIdentifier() && p.to_str() == "f") {
|
||||
next(); // Consume 'f'
|
||||
add_error(p.source(), "float literals must not be suffixed with 'f'");
|
||||
}
|
||||
auto* type = module_.create<ast::type::F32Type>();
|
||||
return create<ast::FloatLiteral>(type, t.to_f32());
|
||||
}
|
||||
|
|
|
@ -209,6 +209,13 @@ TEST_F(ParserImplErrorTest, EqualityInvalidExpr) {
|
|||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, FloatLiteralSuffixedWithF) {
|
||||
EXPECT("var f : f32 = 1.23f;",
|
||||
"test.wgsl:1:19 error: float literals must not be suffixed with 'f'\n"
|
||||
"var f : f32 = 1.23f;\n"
|
||||
" ^\n");
|
||||
}
|
||||
|
||||
TEST_F(ParserImplErrorTest, ForLoopInitializerMissingSemicolon) {
|
||||
EXPECT("fn f() -> void { for (var i : i32 = 0 i < 8; i=i+1) {} }",
|
||||
"test.wgsl:1:39 error: expected ';' for initializer in for loop\n"
|
||||
|
|
Loading…
Reference in New Issue