Skip to content
Open
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
6 changes: 4 additions & 2 deletions crates/cairo-lang-semantic/src/expr/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment on lines +4198 to +4201
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Record shorthand constants in resolved items

When resolve_variable_by_name resolves a statement-level const (Expr::Constant), this new if let Expr::Var path skips inserting any entry into resolved_items. As a result, identifier lookups that rely on lookup_resolved_generic_item_by_ptr / lookup_resolved_concrete_item_by_ptr cannot resolve :x/{ x } shorthand uses of local consts for tooling (e.g., definition/debug mapping), even though the expression now compiles. resolve_expr_path already handles this by inserting a concrete constant entry, so this shorthand path should mirror that behavior.

Useful? React with 👍 / 👎.

Ok(res)
}

Expand Down
23 changes: 23 additions & 0 deletions crates/cairo-lang-semantic/src/expr/test_data/function_call
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading