diff --git a/src/tint/ast/break_if_statement.h b/src/tint/ast/break_if_statement.h index fe83d9234f..1437797bde 100644 --- a/src/tint/ast/break_if_statement.h +++ b/src/tint/ast/break_if_statement.h @@ -22,7 +22,7 @@ namespace tint::ast { -/// A break if statement +/// A break-if statement class BreakIfStatement final : public Castable { public: /// Constructor diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index f704055619..62352ee1e2 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -2456,10 +2456,10 @@ Maybe ParserImpl::break_if_statement() { return Failure::kErrored; } if (!expr.matched) { - return add_error(t1, "expected expression for `break if`"); + return add_error(t1, "expected expression for `break-if`"); } - if (!match(Token::Type::kSemicolon)) { - return add_error(peek(), "expected ';' for `break if` statement"); + if (!expect("`break-if` statement", Token::Type::kSemicolon)) { + return Failure::kErrored; } return create(t1.source(), expr.value); diff --git a/src/tint/reader/wgsl/parser_impl_loop_stmt_test.cc b/src/tint/reader/wgsl/parser_impl_loop_stmt_test.cc index 2b8033f20b..5122332481 100644 --- a/src/tint/reader/wgsl/parser_impl_loop_stmt_test.cc +++ b/src/tint/reader/wgsl/parser_impl_loop_stmt_test.cc @@ -129,7 +129,7 @@ TEST_F(ParserImplTest, LoopStmt_Continuing_BreakIf_MissingExpr) { EXPECT_TRUE(e.errored); EXPECT_TRUE(p->has_error()); EXPECT_EQ(e.value, nullptr); - EXPECT_EQ(p->error(), "1:21: expected expression for `break if`"); + EXPECT_EQ(p->error(), "1:21: expected expression for `break-if`"); } TEST_F(ParserImplTest, LoopStmt_Continuing_BreakIf_InvalidExpr) { @@ -139,7 +139,7 @@ TEST_F(ParserImplTest, LoopStmt_Continuing_BreakIf_InvalidExpr) { EXPECT_TRUE(e.errored); EXPECT_TRUE(p->has_error()); EXPECT_EQ(e.value, nullptr); - EXPECT_EQ(p->error(), "1:21: expected expression for `break if`"); + EXPECT_EQ(p->error(), "1:21: expected expression for `break-if`"); } TEST_F(ParserImplTest, LoopStmt_NoContinuing_BreakIf) { @@ -159,7 +159,7 @@ TEST_F(ParserImplTest, LoopStmt_Continuing_BreakIf_MissingSemicolon) { EXPECT_TRUE(e.errored); EXPECT_TRUE(p->has_error()); EXPECT_EQ(e.value, nullptr); - EXPECT_EQ(p->error(), "1:40: expected ';' for `break if` statement"); + EXPECT_EQ(p->error(), "1:40: expected ';' for `break-if` statement"); } } // namespace diff --git a/src/tint/resolver/validation_test.cc b/src/tint/resolver/validation_test.cc index c86a040095..d784971048 100644 --- a/src/tint/resolver/validation_test.cc +++ b/src/tint/resolver/validation_test.cc @@ -1126,7 +1126,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfTrueInContinuing) { EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead."); + "from a continuing block. Use `break-if` instead."); } TEST_F(ResolverValidationTest, Stmt_BreakInIfElseInContinuing) { @@ -1140,7 +1140,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseInContinuing) { EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead."); + "from a continuing block. Use `break-if` instead."); } TEST_F(ResolverValidationTest, Stmt_BreakInContinuing) { @@ -1151,7 +1151,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInContinuing) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" @@ -1170,7 +1170,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfInIfInContinuing) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" @@ -1189,7 +1189,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfTrueMultipleStmtsInContinuing) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" @@ -1208,7 +1208,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseMultipleStmtsInContinuing) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" @@ -1226,7 +1226,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseIfInContinuing) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" @@ -1245,7 +1245,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfNonEmptyElseInContinuing) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" @@ -1264,7 +1264,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfElseNonEmptyTrueInContinuing) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" @@ -1282,7 +1282,7 @@ TEST_F(ResolverValidationTest, Stmt_BreakInIfInContinuingNotLast) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 warning: use of deprecated language feature: `break` must not be used to exit " - "from a continuing block. Use break-if instead.\n" + "from a continuing block. Use `break-if` instead.\n" "12:34 error: break statement in a continuing block must be the single " "statement of an if statement's true or false block, and that if " "statement must be the last statement of the continuing block\n" diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index 2355b6a5c2..9c693dcd0d 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -1465,7 +1465,7 @@ bool Validator::BreakStatement(const sem::Statement* stmt, if (auto* continuing = ClosestContinuing(/*stop_at_loop*/ true, current_statement)) { AddWarning( "use of deprecated language feature: `break` must not be used to exit from " - "a continuing block. Use break-if instead.", + "a continuing block. Use `break-if` instead.", stmt->Declaration()->source); auto fail = [&](const char* note_msg, const Source& note_src) { @@ -1651,9 +1651,8 @@ bool Validator::BreakIfStatement(const sem::BreakIfStatement* stmt, if (s->Is()) { break; } - if (s->Is()) { - if (s->Declaration()->As()->statements.Back() != - stmt->Declaration()) { + if (auto* continuing = s->As()) { + if (continuing->Declaration()->statements.Back() != stmt->Declaration()) { AddError("break-if must be last statement in a continuing block", stmt->Declaration()->source); AddNote("see continuing block here", s->Declaration()->source); diff --git a/src/tint/sem/loop_statement.cc b/src/tint/sem/loop_statement.cc index eee735ce2b..1d4db8a236 100644 --- a/src/tint/sem/loop_statement.cc +++ b/src/tint/sem/loop_statement.cc @@ -40,4 +40,8 @@ LoopContinuingBlockStatement::LoopContinuingBlockStatement(const ast::BlockState } LoopContinuingBlockStatement::~LoopContinuingBlockStatement() = default; +const ast::BlockStatement* LoopContinuingBlockStatement::Declaration() const { + return static_cast(Base::Declaration()); +} + } // namespace tint::sem diff --git a/src/tint/sem/loop_statement.h b/src/tint/sem/loop_statement.h index 502fa7ce86..6dc7037fba 100644 --- a/src/tint/sem/loop_statement.h +++ b/src/tint/sem/loop_statement.h @@ -53,6 +53,9 @@ class LoopContinuingBlockStatement final /// Destructor ~LoopContinuingBlockStatement() override; + + /// @returns the AST node + const ast::BlockStatement* Declaration() const; }; } // namespace tint::sem diff --git a/test/tint/bug/tint/1064.wgsl.expected.dxc.hlsl b/test/tint/bug/tint/1064.wgsl.expected.dxc.hlsl index a739de0899..be35136622 100644 --- a/test/tint/bug/tint/1064.wgsl.expected.dxc.hlsl +++ b/test/tint/bug/tint/1064.wgsl.expected.dxc.hlsl @@ -1,4 +1,4 @@ -bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead. +bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use `break-if` instead. break; ^^^^^ diff --git a/test/tint/bug/tint/1064.wgsl.expected.fxc.hlsl b/test/tint/bug/tint/1064.wgsl.expected.fxc.hlsl index a739de0899..be35136622 100644 --- a/test/tint/bug/tint/1064.wgsl.expected.fxc.hlsl +++ b/test/tint/bug/tint/1064.wgsl.expected.fxc.hlsl @@ -1,4 +1,4 @@ -bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead. +bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use `break-if` instead. break; ^^^^^ diff --git a/test/tint/bug/tint/1064.wgsl.expected.glsl b/test/tint/bug/tint/1064.wgsl.expected.glsl index 2a91c86d54..b181e85a4a 100644 --- a/test/tint/bug/tint/1064.wgsl.expected.glsl +++ b/test/tint/bug/tint/1064.wgsl.expected.glsl @@ -1,4 +1,4 @@ -bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead. +bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use `break-if` instead. break; ^^^^^ diff --git a/test/tint/bug/tint/1064.wgsl.expected.msl b/test/tint/bug/tint/1064.wgsl.expected.msl index 212a90d8c3..7a8759a89b 100644 --- a/test/tint/bug/tint/1064.wgsl.expected.msl +++ b/test/tint/bug/tint/1064.wgsl.expected.msl @@ -1,4 +1,4 @@ -bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead. +bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use `break-if` instead. break; ^^^^^ diff --git a/test/tint/bug/tint/1064.wgsl.expected.spvasm b/test/tint/bug/tint/1064.wgsl.expected.spvasm index 1cb1a4ee7c..1051a7aa41 100644 --- a/test/tint/bug/tint/1064.wgsl.expected.spvasm +++ b/test/tint/bug/tint/1064.wgsl.expected.spvasm @@ -1,4 +1,4 @@ -bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead. +bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use `break-if` instead. break; ^^^^^ diff --git a/test/tint/bug/tint/1064.wgsl.expected.wgsl b/test/tint/bug/tint/1064.wgsl.expected.wgsl index 145f05dd8a..d267bdbd92 100644 --- a/test/tint/bug/tint/1064.wgsl.expected.wgsl +++ b/test/tint/bug/tint/1064.wgsl.expected.wgsl @@ -1,4 +1,4 @@ -bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead. +bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use `break-if` instead. break; ^^^^^