Skip to content

Commit

Permalink
Fix break returns neveR (#3412)
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware authored Jun 14, 2023
1 parent 7d87b08 commit d933558
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/cairo-lang-semantic/src/expr/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ pub fn compute_expr_block_semantic(
let ty = if let Some(t) = &tail_semantic_expr {
t.ty()
} else if let Some(statement) = statements_semantic.last() {
if let Statement::Return(_) = &new_ctx.statements[*statement] {
if let Statement::Return(_) | Statement::Break(_) = &new_ctx.statements[*statement] {
never_ty(new_ctx.db)
} else {
unit_ty(db)
Expand Down
1 change: 1 addition & 0 deletions tests/bug_samples/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ mod issue3345;
mod loop_only_change;
mod inconsistent_gas;
mod partial_param_local;
mod loop_break_in_match;
25 changes: 25 additions & 0 deletions tests/bug_samples/loop_break_in_match.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use core::array::ArrayTrait;
use core::debug::PrintTrait;

#[available_gas(2000000)]
#[test]
fn main() {
let mut a: Array<felt252> = ArrayTrait::new();
a.append('a');
a.append('b');

let a = loop {
let v: felt252 = match a.pop_front() {
Option::Some(v) => {
v
},
Option::None(()) => {
break 'hi';
}
};

v.print();
};

a.print();
}

0 comments on commit d933558

Please sign in to comment.