diff --git a/crates/cairo-lang-semantic/src/expr/compute.rs b/crates/cairo-lang-semantic/src/expr/compute.rs index 0f361753147..0f58f168446 100644 --- a/crates/cairo-lang-semantic/src/expr/compute.rs +++ b/crates/cairo-lang-semantic/src/expr/compute.rs @@ -4195,8 +4195,10 @@ pub fn resolve_variable_by_name<'db>( let res = get_binded_expr_by_name(ctx, variable_name, false, stable_ptr).ok_or_else(|| { ctx.diagnostics.report(identifier.stable_ptr(ctx.db), VariableNotFound(variable_name)) })?; - let item = ResolvedGenericItem::Variable(extract_matches!(&res, Expr::Var).var); - ctx.resolver.data.resolved_items.generic.insert(identifier.stable_ptr(ctx.db), item); + if let Expr::Var(expr_var) = &res { + let item = ResolvedGenericItem::Variable(expr_var.var); + ctx.resolver.data.resolved_items.generic.insert(identifier.stable_ptr(ctx.db), item); + } Ok(res) } diff --git a/crates/cairo-lang-semantic/src/expr/test_data/function_call b/crates/cairo-lang-semantic/src/expr/test_data/function_call index 9aa8e1010b1..8e3ca769c11 100644 --- a/crates/cairo-lang-semantic/src/expr/test_data/function_call +++ b/crates/cairo-lang-semantic/src/expr/test_data/function_call @@ -300,3 +300,26 @@ error[E2042]: Unexpected return type. Expected: "core::integer::u8", found: "cor --> lib.cairo:2:11 || -> u8 { ^^ + +//! > ========================================================================== + +//! > Statement-level const used in named argument shorthand. + +//! > test_runner_name +test_function_diagnostics(expect_diagnostics: false) + +//! > function_code +fn foo() -> felt252 { + const x: felt252 = 42; + takes_val(:x) +} + +//! > function_name +foo + +//! > module_code +fn takes_val(x: felt252) -> felt252 { + x +} + +//! > expected_diagnostics