diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc index 7e3064d62a..fdc9df7c6f 100644 --- a/src/reader/wgsl/parser_impl.cc +++ b/src/reader/wgsl/parser_impl.cc @@ -1021,12 +1021,6 @@ std::unique_ptr ParserImpl::struct_decl() { return nullptr; } - t = peek(); - if (!t.IsBraceLeft()) { - set_error(t, "missing { for struct declaration"); - return nullptr; - } - auto body = struct_body_decl(); if (has_error()) { return nullptr; @@ -1075,14 +1069,17 @@ ast::StructDecoration ParserImpl::struct_decoration(Token t) { // : BRACKET_LEFT struct_member* BRACKET_RIGHT ast::StructMemberList ParserImpl::struct_body_decl() { auto t = peek(); - if (!t.IsBraceLeft()) + if (!t.IsBraceLeft()) { + set_error(t, "missing { for struct declaration"); return {}; - + } next(); // Consume the peek t = peek(); - if (t.IsBraceRight()) + if (t.IsBraceRight()) { + next(); // Consume the peek return {}; + } ast::StructMemberList members; for (;;) { diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc index 383a0359fc..2995881b60 100644 --- a/src/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/reader/wgsl/parser_impl_type_alias_test.cc @@ -109,6 +109,24 @@ TEST_F(ParserImplTest, TypeDecl_Struct_WithStride) { EXPECT_EQ(arr->array_stride(), 4u); } +// This was failing due to not finding the missing ;. https://crbug.com/tint/218 +TEST_F(ParserImplTest, TypeDecl_Struct_Empty) { + auto* p = parser("type str = struct {};"); + p->global_decl(); + ASSERT_FALSE(p->has_error()) << p->error(); + + auto module = p->module(); + ASSERT_EQ(module.alias_types().size(), 1u); + + auto* t = module.alias_types()[0]; + ASSERT_NE(t, nullptr); + EXPECT_EQ(t->name(), "str"); + + ASSERT_TRUE(t->type()->IsStruct()); + auto* s = t->type()->AsStruct(); + EXPECT_EQ(s->impl()->members().size(), 0u); +} + } // namespace } // namespace wgsl } // namespace reader