diff --git a/crates/sema/src/ast_passes.rs b/crates/sema/src/ast_passes.rs index 26fa4d7..8ef62d8 100644 --- a/crates/sema/src/ast_passes.rs +++ b/crates/sema/src/ast_passes.rs @@ -89,9 +89,20 @@ impl<'ast> Visit<'ast> for AstValidator<'_> { self.walk_stmt(body); self.in_loop_depth -= 1; } - StmtKind::Break | StmtKind::Continue => { + StmtKind::Break => { if !self.in_loop() { - self.dcx().err("`break` outside of a loop").span(stmt.span).emit(); + self.dcx() + .err("\"break\" has to be in a \"for\" or \"while\" loop.") + .span(stmt.span) + .emit(); + } + } + StmtKind::Continue => { + if !self.in_loop() { + self.dcx() + .err("\"continue\" has to be in a \"for\" or \"while\" loop.") + .span(stmt.span) + .emit(); } } _ => {} diff --git a/tests/ui/parser/break_continue_outside_loop.sol b/tests/ui/parser/break_continue_outside_loop.sol index 9369c73..1359778 100644 --- a/tests/ui/parser/break_continue_outside_loop.sol +++ b/tests/ui/parser/break_continue_outside_loop.sol @@ -1,7 +1,7 @@ contract C { function f() { - break; //~ ERROR: `break` outside of a loop - continue; //~ ERROR: `break` outside of a loop + break; //~ ERROR: "break" has to be in a "for" or "while" loop. + continue; //~ ERROR: "continue" has to be in a "for" or "while" loop. for (uint256 i = 0; i < 10; i++) { break; diff --git a/tests/ui/parser/break_continue_outside_loop.stderr b/tests/ui/parser/break_continue_outside_loop.stderr index 387a8ac..190bcb8 100644 --- a/tests/ui/parser/break_continue_outside_loop.stderr +++ b/tests/ui/parser/break_continue_outside_loop.stderr @@ -1,11 +1,11 @@ -error: `break` outside of a loop +error: "break" has to be in a "for" or "while" loop. --> ROOT/tests/ui/parser/break_continue_outside_loop.sol:LL:CC | LL | break; | ^^^^^^ | -error: `break` outside of a loop +error: "continue" has to be in a "for" or "while" loop. --> ROOT/tests/ui/parser/break_continue_outside_loop.sol:LL:CC | LL | continue;