Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt committed Nov 11, 2024
1 parent 62dcca7 commit f71cf07
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 2 additions & 7 deletions crates/sema/src/ast_passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,10 @@ impl<'ast> Visit<'ast> for AstValidator<'_> {
}
StmtKind::Break => {
if !self.in_loop() {
self.dcx()
.err("\"break\" has to be in a \"for\" or \"while\" loop.")
.span(self.span)
.emit();
self.dcx().err("`break` outside of a loop").span(self.span).emit();
}
}
_ => {
self.visit_stmt(stmt);
}
_ => {}
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/ui/parser/break_outside_loop.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function f() {
break; //~^ERROR: `break` outside of a loop
}
11 changes: 11 additions & 0 deletions tests/ui/parser/break_outside_loop.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: `break` outside of a loop
--> ROOT/tests/ui/parser/break_outside_loop.sol:LL:CC
|
LL | / function f() {
LL | | break;
LL | | }
| |_^
|

error: aborting due to 1 previous error

0 comments on commit f71cf07

Please sign in to comment.