Sitelet https://github.com/starkware-libs/cairo/commit/7ba1a925b610c239cd8b68e6037d845745848571
Skip to content

Commit 7ba1a92

Browse files
committed
fix(semantic): point const-decl literal errors at the value expression
When a numeric literal binds to a non-numeric type in a `const` declaration, the conform-time error now attaches to the value expression's stable_ptr instead of the whole `const … = …;` span.
1 parent 4de27f4 commit 7ba1a92

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎crates/cairo-lang-semantic/src/expr/test_data/closure‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ error[E2182]: Closures are not allowed in this context.
120120
|_^
121121

122122
error[E2302]: Type mismatch: `{closure@lib.cairo:1:17: 1:19}` and `core::integer::i32`.
123-
--> lib.cairo:1:1-4:2
123+
--> lib.cairo:1:17-4:1
124124
const _x: i32 = || {
125-
_^
125+
_________________^
126126
| ...
127127
| };
128-
|__^
128+
|_^
129129

130130
//! > ==========================================================================
131131

‎crates/cairo-lang-semantic/src/expr/test_data/constant‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ error[E2125]: The '?' operator is not supported outside of functions.
136136
^^^^^^^^^^^^^^^^^^^^^^^^^^^
137137

138138
error[E2311]: Mismatched types. The type `core::bool` cannot be created from a numeric literal.
139-
--> lib.cairo:6:1
139+
--> lib.cairo:6:42
140140
const WRONG_TYPE_AND_NOT_LITERAL: bool = 1 + 2;
141-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
141+
^^^^^
142142

143143
error[E2127]: This expression is not supported as constant.
144144
--> lib.cairo:14:47
@@ -191,9 +191,9 @@ const DEFAULT_VAR: bool = 1;
191191

192192
//! > expected_diagnostics
193193
error[E2311]: Mismatched types. The type `core::bool` cannot be created from a numeric literal.
194-
--> lib.cairo:1:1
194+
--> lib.cairo:1:27
195195
const DEFAULT_VAR: bool = 1;
196-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
196+
^
197197

198198
//! > ==========================================================================
199199

‎crates/cairo-lang-semantic/src/items/constant.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ pub fn resolve_const_expr_and_evaluate<'db, 'mt>(
465465
let mut_ref = &mut ctx.resolver;
466466
let mut inference: crate::expr::inference::Inference<'db, '_> = mut_ref.inference();
467467
if let Err(err_set) = inference.conform_ty(value.ty(), target_type) {
468-
inference.report_on_pending_error(err_set, ctx.diagnostics, const_stable_ptr);
468+
inference.report_on_pending_error(err_set, ctx.diagnostics, value.stable_ptr().untyped());
469469
}
470470

471471
if finalize {

‎crates/cairo-lang-semantic/src/items/tests/trait_const‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ impl MyImpl of MyTrait {
645645

646646
//! > expected_diagnostics
647647
error[E2302]: Type mismatch: `core::integer::u32` and `core::integer::u16`.
648-
--> lib.cairo:6:5
648+
--> lib.cairo:6:20
649649
const X: u16 = Self::Y;
650-
^^^^^^^^^^^^^^^^^^^^^^^
650+
^^^^^^^
651651

652652
//! > ==========================================================================
653653

0 commit comments

Comments
 (0)