Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made sure closure type isn't var free if it captured vars. #7255

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/cairo-lang-semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cairo_lang_syntax::attribute::consts::MUST_USE_ATTR;
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
use cairo_lang_syntax::node::{TypedStablePtr, TypedSyntaxNode, ast};
use cairo_lang_utils::{Intern, LookupIntern, OptionFrom, define_short_id, try_extract_matches};
use itertools::Itertools;
use itertools::{Itertools, chain};
use num_bigint::BigInt;
use num_traits::Zero;
use sha3::{Digest, Keccak256};
Expand Down Expand Up @@ -946,7 +946,7 @@ pub fn priv_type_is_var_free(db: &dyn SemanticGroup, ty: TypeId) -> bool {
// a var free ImplType needs to be rewritten if has impl bounds constraints.
TypeLongId::ImplType(_) => false,
TypeLongId::Closure(closure) => {
closure.param_tys.iter().all(|param| param.is_var_free(db))
chain!(&closure.captured_types, &closure.param_tys).all(|param| param.is_var_free(db))
&& closure.ret_ty.is_var_free(db)
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/bug_samples/issue7233.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[test]
fn stack_overflow() {
let outer_var = 42;
let closure_annotated = |i: u32| -> u32 {
i + outer_var
};
let _v = closure_annotated(1);
}
1 change: 1 addition & 0 deletions tests/bug_samples/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ mod issue7071;
mod issue7083;
mod issue7095;
mod issue7155;
mod issue7233;
mod loop_break_in_match;
mod loop_only_change;
mod partial_param_local;
Expand Down