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

Commit d47df27

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 8fa481e commit d47df27

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
@@ -248,9 +248,9 @@ error[E2125]: The '?' operator is not supported outside of functions.
248248
^^^^^^^^^^^^^^^^^^^^^^^^^^^
249249

250250
error[E2315]: Mismatched types. The type `core::bool` cannot be created from a numeric literal.
251-
--> lib.cairo:6:1
251+
--> lib.cairo:6:42
252252
const WRONG_TYPE_AND_NOT_LITERAL: bool = 1 + 2;
253-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
253+
^^^^^
254254

255255
error[E2127]: This expression is not supported as constant.
256256
--> lib.cairo:14:47
@@ -308,9 +308,9 @@ const DEFAULT_VAR: bool = 1;
308308

309309
//! > expected_diagnostics
310310
error[E2315]: Mismatched types. The type `core::bool` cannot be created from a numeric literal.
311-
--> lib.cairo:1:1
311+
--> lib.cairo:1:27
312312
const DEFAULT_VAR: bool = 1;
313-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313+
^
314314

315315
//! > ==========================================================================
316316

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

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

470470
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)