diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 5d056aec03..cbfbc461f0 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -1679,14 +1679,16 @@ Expect ParserImpl::expect_compound_statement(std::string_v // : attribute* BRACE_LEFT statement* BRACE_RIGHT Expect ParserImpl::expect_compound_statement(AttributeList& attrs, std::string_view use) { - return expect_brace_block(use, [&]() -> Expect { - auto stmts = expect_statements(); - if (stmts.errored) { - return Failure::kErrored; - } - TINT_DEFER(attrs.Clear()); - return create(Source{}, stmts.value, std::move(attrs)); - }); + auto source_start = peek().source(); + auto stmts = + expect_brace_block(use, [&]() -> Expect { return expect_statements(); }); + auto source_end = last_source(); + if (stmts.errored) { + return Failure::kErrored; + } + TINT_DEFER(attrs.Clear()); + return create(Source::Combine(source_start, source_end), stmts.value, + std::move(attrs)); } // paren_expression diff --git a/src/tint/reader/wgsl/parser_impl_compound_stmt_test.cc b/src/tint/reader/wgsl/parser_impl_compound_stmt_test.cc index f096fd670f..514c8005c8 100644 --- a/src/tint/reader/wgsl/parser_impl_compound_stmt_test.cc +++ b/src/tint/reader/wgsl/parser_impl_compound_stmt_test.cc @@ -24,6 +24,12 @@ TEST_F(ParserImplTest, CompoundStmt) { return 1 + b / 2; })"); auto e = p->expect_compound_statement(""); + + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 1u); + EXPECT_EQ(e->source.range.end.line, 4u); + EXPECT_EQ(e->source.range.end.column, 2u); + ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); ASSERT_EQ(e->statements.Length(), 2u); @@ -34,6 +40,12 @@ TEST_F(ParserImplTest, CompoundStmt) { TEST_F(ParserImplTest, CompoundStmt_Empty) { auto p = parser("{}"); auto e = p->expect_compound_statement(""); + + EXPECT_EQ(e->source.range.begin.line, 1u); + EXPECT_EQ(e->source.range.begin.column, 1u); + EXPECT_EQ(e->source.range.end.line, 1u); + EXPECT_EQ(e->source.range.end.column, 3u); + ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_FALSE(e.errored); EXPECT_EQ(e->statements.Length(), 0u);