tint: Make the error message on `enable(f16)` more clear

Explicitly call out that enable directives don't take parenthesis
instead of saying "invalid extension name".

Bug: tint:1620
Change-Id: I124568fdee2fa5bddf1426bed52762a329bd5d9f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96686
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Corentin Wallez 2022-07-21 15:53:55 +00:00 committed by Dawn LUCI CQ
parent 5716611bf0
commit a84b9119eb
2 changed files with 16 additions and 0 deletions

View File

@ -363,6 +363,10 @@ Maybe<bool> ParserImpl::enable_directive() {
synchronized_ = true;
next();
name = {"f16", t.source()};
} else if (t.Is(Token::Type::kParenLeft)){
// A common error case is writing `enable(foo);` instead of `enable foo;`.
synchronized_ = false;
return add_error(t.source(), "enable directives don't take parenthesis");
} else if (handle_error(t)) {
// The token might itself be an error.
return Failure::kErrored;

View File

@ -80,6 +80,18 @@ TEST_F(EnableDirectiveTest, MissingEndingSemicolon) {
EXPECT_EQ(ast.GlobalDeclarations().size(), 0u);
}
// Test the special error message when enable are used with parenthesis.
TEST_F(EnableDirectiveTest, ParenthesisSpecialCase) {
auto p = parser("enable(f16);");
p->translation_unit();
EXPECT_TRUE(p->has_error());
EXPECT_EQ(p->error(), "1:7: enable directives don't take parenthesis");
auto program = p->program();
auto& ast = program.AST();
EXPECT_EQ(ast.Enables().size(), 0u);
EXPECT_EQ(ast.GlobalDeclarations().size(), 0u);
}
// Test using invalid tokens in an enable directive.
TEST_F(EnableDirectiveTest, InvalidTokens) {
{