Skip to content

Commit

Permalink
Made sure closure would have the same id on call and defintion.
Browse files Browse the repository at this point in the history
Closes #6920
  • Loading branch information
orizi committed Dec 25, 2024
1 parent 809dfef commit b611190
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/cairo-lang-lowering/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,16 @@ pub trait SemanticFunctionIdEx {
}
impl SemanticFunctionIdEx for semantic::FunctionId {
fn lowered(&self, db: &dyn LoweringGroup) -> FunctionId {
FunctionLongId::Semantic(*self).intern(db)
let ret = FunctionLongId::Semantic(*self).intern(db);
// If the function is generated, we need to check if it has a body, so we can return its
// generated function id.
// TODO(orizi): This is a hack, we should have a better way to do this.
if let Ok(Some(body)) = ret.body(db) {
if let Ok(id) = body.function_id(db) {
return id;
}
}
ret
}
}
impl<'a> DebugWithDb<dyn LoweringGroup + 'a> for FunctionLongId {
Expand Down
4 changes: 4 additions & 0 deletions tests/bug_samples/cairo_project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ bug_samples = "."

[config.global]
edition = "2023_10"

[config.global.experimental_features]
negative_impls = true
associated_item_constraints = true
11 changes: 11 additions & 0 deletions tests/bug_samples/issue6920.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[test]
fn uninlined_closure_test() {
let uninlined_closure =
|| {
let a: felt252 = 256;
format!(
"wow such amazing calcs {a} wow such amazing calcs {a} wow such amazing calcs {a}",
);
};
let _ = uninlined_closure();
}
1 change: 1 addition & 0 deletions tests/bug_samples/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ mod issue5967;
mod issue6580;
mod issue6623;
mod issue6755;
mod issue6920;
mod loop_break_in_match;
mod loop_only_change;
mod partial_param_local;
Expand Down

0 comments on commit b611190

Please sign in to comment.