Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Nov 11, 2024
1 parent f71cf07 commit 0d9efa4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
15 changes: 6 additions & 9 deletions crates/sema/src/ast_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,16 @@ impl<'ast> Visit<'ast> for AstValidator<'_> {
let Stmt { kind, .. } = stmt;

match kind {
StmtKind::DoWhile(stmt, ..) => {
StmtKind::While(_, body, ..)
| StmtKind::DoWhile(body, ..)
| StmtKind::For { body, .. } => {
self.in_loop_depth += 1;
self.visit_stmt(stmt);
self.walk_stmt(body);
self.in_loop_depth -= 1;
}
StmtKind::For { body, .. } => {
self.in_loop_depth += 1;
self.visit_stmt(body);
self.in_loop_depth -= 1;
}
StmtKind::Break => {
StmtKind::Break | StmtKind::Continue => {
if !self.in_loop() {
self.dcx().err("`break` outside of a loop").span(self.span).emit();
self.dcx().err("`break` outside of a loop").span(stmt.span).emit();
}
}
_ => {}
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/parser/break_continue_outside_loop.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
contract C {
function f() {
break; //~ ERROR: `break` outside of a loop
continue; //~ ERROR: `break` outside of a loop

for (uint256 i = 0; i < 10; i++) {
break;
continue;
}

while (true) {
break;
continue;
}

do {
break;
continue;
} while (true);
}
}
16 changes: 16 additions & 0 deletions tests/ui/parser/break_continue_outside_loop.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: `break` outside of a loop
--> ROOT/tests/ui/parser/break_continue_outside_loop.sol:LL:CC
|
LL | break;
| ^^^^^^
|

error: `break` outside of a loop
--> ROOT/tests/ui/parser/break_continue_outside_loop.sol:LL:CC
|
LL | continue;
| ^^^^^^^^^
|

error: aborting due to 2 previous errors

3 changes: 0 additions & 3 deletions tests/ui/parser/break_outside_loop.sol

This file was deleted.

11 changes: 0 additions & 11 deletions tests/ui/parser/break_outside_loop.stderr

This file was deleted.

0 comments on commit 0d9efa4

Please sign in to comment.