diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index cc245cdd86..93fbc112d1 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -1383,18 +1383,7 @@ Expect ParserImpl::expect_type_specifier_matrix(const Source& // // Note, we also parse `push_constant` from the experimental extension Expect ParserImpl::expect_address_space(std::string_view use) { - auto& t = peek(); - auto ident = expect_ident("address space"); - if (ident.errored) { - return Failure::kErrored; - } - - auto address_space = ast::ParseAddressSpace(ident.value); - if (address_space == ast::AddressSpace::kInvalid) { - return add_error(t.source(), "invalid address space", use); - } - - return {address_space, t.source()}; + return expect_enum("address space", ast::ParseAddressSpace, ast::kAddressSpaceStrings, use); } // struct_decl diff --git a/src/tint/reader/wgsl/parser_impl_address_space_test.cc b/src/tint/reader/wgsl/parser_impl_address_space_test.cc index d9d6d5ec8d..251c1d0ec0 100644 --- a/src/tint/reader/wgsl/parser_impl_address_space_test.cc +++ b/src/tint/reader/wgsl/parser_impl_address_space_test.cc @@ -54,7 +54,8 @@ TEST_F(ParserImplTest, AddressSpace_NoMatch) { auto sc = p->expect_address_space("test"); EXPECT_EQ(sc.errored, true); EXPECT_TRUE(p->has_error()); - EXPECT_EQ(p->error(), "1:1: invalid address space for test"); + EXPECT_EQ(p->error(), R"(1:1: expected address space for test +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } } // namespace diff --git a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc index e60652f7f0..af9734c0fe 100644 --- a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc +++ b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc @@ -1112,7 +1112,8 @@ var i : ptr; TEST_F(ParserImplErrorTest, GlobalDeclVarPtrMissingAddressSpace) { EXPECT("var i : ptr;", - R"(test.wgsl:1:13 error: invalid address space for ptr declaration + R"(test.wgsl:1:13 error: expected address space for ptr declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup' var i : ptr; ^^^^ )"); @@ -1144,7 +1145,8 @@ var i : atomic i : i32", - R"(test.wgsl:1:5 error: invalid address space for variable declaration + R"(test.wgsl:1:5 error: expected address space for variable declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup' var i : i32 ^^^^ )"); diff --git a/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc index d6e475a74c..388ad6702b 100644 --- a/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -165,7 +165,8 @@ TEST_F(ParserImplTest, GlobalVariableDecl_InvalidVariableDecl) { EXPECT_TRUE(e.errored); EXPECT_FALSE(e.matched); EXPECT_EQ(e.value, nullptr); - EXPECT_EQ(p->error(), "1:5: invalid address space for variable declaration"); + EXPECT_EQ(p->error(), R"(1:5: expected address space for variable declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } } // namespace diff --git a/src/tint/reader/wgsl/parser_impl_type_decl_test.cc b/src/tint/reader/wgsl/parser_impl_type_decl_test.cc index 0e018e07e2..d01d8a14f9 100644 --- a/src/tint/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_type_decl_test.cc @@ -272,7 +272,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingAddressSpace) { EXPECT_FALSE(t.matched); ASSERT_EQ(t.value, nullptr); ASSERT_TRUE(p->has_error()); - ASSERT_EQ(p->error(), "1:5: expected identifier for address space"); + ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, TypeDecl_Ptr_MissingType) { @@ -302,7 +303,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_MissingParams) { EXPECT_FALSE(t.matched); ASSERT_EQ(t.value, nullptr); ASSERT_TRUE(p->has_error()); - ASSERT_EQ(p->error(), "1:5: expected identifier for address space"); + ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, TypeDecl_Ptr_BadAddressSpace) { @@ -312,7 +314,9 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_BadAddressSpace) { EXPECT_FALSE(t.matched); ASSERT_EQ(t.value, nullptr); ASSERT_TRUE(p->has_error()); - ASSERT_EQ(p->error(), "1:5: invalid address space for ptr declaration"); + ASSERT_EQ(p->error(), + R"(1:5: expected address space for ptr declaration. Did you mean 'uniform'? +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, TypeDecl_Ptr_BadAccess) { diff --git a/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc b/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc index 186b3648b9..c9bee2b2a2 100644 --- a/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc +++ b/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc @@ -263,7 +263,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_MissingAddressSpace) { EXPECT_FALSE(t.matched); ASSERT_EQ(t.value, nullptr); ASSERT_TRUE(p->has_error()); - ASSERT_EQ(p->error(), "1:5: expected identifier for address space"); + ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_MissingType) { @@ -293,7 +294,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_MissingParams) { EXPECT_FALSE(t.matched); ASSERT_EQ(t.value, nullptr); ASSERT_TRUE(p->has_error()); - ASSERT_EQ(p->error(), "1:5: expected identifier for address space"); + ASSERT_EQ(p->error(), R"(1:5: expected address space for ptr declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAddressSpace) { @@ -303,7 +305,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAddressSpace) { EXPECT_FALSE(t.matched); ASSERT_EQ(t.value, nullptr); ASSERT_TRUE(p->has_error()); - ASSERT_EQ(p->error(), "1:5: invalid address space for ptr declaration"); + ASSERT_EQ(p->error(), + R"(1:5: expected address space for ptr declaration. Did you mean 'uniform'? +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_BadAccess) { diff --git a/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc b/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc index 8427c6e950..5cf038bcd2 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc @@ -105,7 +105,9 @@ TEST_F(ParserImplTest, VariableDecl_InvalidAddressSpace) { EXPECT_FALSE(v.matched); EXPECT_TRUE(v.errored); EXPECT_TRUE(p->has_error()); - EXPECT_EQ(p->error(), "1:5: invalid address space for variable declaration"); + EXPECT_EQ(p->error(), + R"(1:5: expected address space for variable declaration. Did you mean 'uniform'? +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } } // namespace diff --git a/src/tint/reader/wgsl/parser_impl_variable_qualifier_test.cc b/src/tint/reader/wgsl/parser_impl_variable_qualifier_test.cc index 9f8663d9c0..5c0cd5ef32 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_qualifier_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_qualifier_test.cc @@ -63,7 +63,8 @@ TEST_F(ParserImplTest, VariableQualifier_NoMatch) { EXPECT_TRUE(p->has_error()); EXPECT_TRUE(sc.errored); EXPECT_FALSE(sc.matched); - EXPECT_EQ(p->error(), "1:2: invalid address space for variable declaration"); + EXPECT_EQ(p->error(), R"(1:2: expected address space for variable declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, VariableQualifier_Empty) { @@ -72,7 +73,8 @@ TEST_F(ParserImplTest, VariableQualifier_Empty) { EXPECT_TRUE(p->has_error()); EXPECT_TRUE(sc.errored); EXPECT_FALSE(sc.matched); - EXPECT_EQ(p->error(), "1:2: expected identifier for address space"); + EXPECT_EQ(p->error(), R"(1:2: expected address space for variable declaration +Possible values: 'function', 'private', 'push_constant', 'storage', 'uniform', 'workgroup')"); } TEST_F(ParserImplTest, VariableQualifier_MissingLessThan) {