Skip to content

Commit f9dc370

Browse files
committed
fix: allow statement-level consts in named argument shorthand instead of panicking
Fixes #9789
1 parent 3855e3f commit f9dc370

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

crates/cairo-lang-semantic/src/expr/compute.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,8 +4195,10 @@ pub fn resolve_variable_by_name<'db>(
41954195
let res = get_binded_expr_by_name(ctx, variable_name, false, stable_ptr).ok_or_else(|| {
41964196
ctx.diagnostics.report(identifier.stable_ptr(ctx.db), VariableNotFound(variable_name))
41974197
})?;
4198-
let item = ResolvedGenericItem::Variable(extract_matches!(&res, Expr::Var).var);
4199-
ctx.resolver.data.resolved_items.generic.insert(identifier.stable_ptr(ctx.db), item);
4198+
if let Expr::Var(expr_var) = &res {
4199+
let item = ResolvedGenericItem::Variable(expr_var.var);
4200+
ctx.resolver.data.resolved_items.generic.insert(identifier.stable_ptr(ctx.db), item);
4201+
}
42004202
Ok(res)
42014203
}
42024204

crates/cairo-lang-semantic/src/expr/test_data/function_call

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,26 @@ error[E2042]: Unexpected return type. Expected: "core::integer::u8", found: "cor
300300
--> lib.cairo:2:11
301301
|| -> u8 {
302302
^^
303+
304+
//! > ==========================================================================
305+
306+
//! > Statement-level const used in named argument shorthand.
307+
308+
//! > test_runner_name
309+
test_function_diagnostics(expect_diagnostics: false)
310+
311+
//! > function_code
312+
fn foo() -> felt252 {
313+
const x: felt252 = 42;
314+
takes_val(:x)
315+
}
316+
317+
//! > function_name
318+
foo
319+
320+
//! > module_code
321+
fn takes_val(x: felt252) -> felt252 {
322+
x
323+
}
324+
325+
//! > expected_diagnostics

0 commit comments

Comments
 (0)