diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index f914bd4ee1..8e5c0cf672 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -2622,6 +2622,11 @@ Maybe ParserImpl::const_literal() { return create(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(); return create(type, t.to_f32()); } diff --git a/src/reader/wgsl/parser_impl_error_msg_test.cc b/src/reader/wgsl/parser_impl_error_msg_test.cc index cf5906bd31..8a533358b4 100644 --- a/src/reader/wgsl/parser_impl_error_msg_test.cc +++ b/src/reader/wgsl/parser_impl_error_msg_test.cc @@ -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"