Skip to content

Commit

Permalink
Refactored const evaluation by usage of context. (#6977)
Browse files Browse the repository at this point in the history
  • Loading branch information
orizi authored Jan 5, 2025
1 parent 6f48877 commit eabc3e0
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 268 deletions.
1 change: 1 addition & 0 deletions crates/cairo-lang-semantic/src/expr/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3610,6 +3610,7 @@ pub fn compute_statement_semantic(
&rhs_expr,
stmt_item_syntax.stable_ptr().untyped(),
explicit_type,
false,
);
let name_syntax = const_syntax.name(syntax_db);
let name = name_syntax.text(db.upcast());
Expand Down
61 changes: 0 additions & 61 deletions crates/cairo-lang-semantic/src/expr/test_data/constant
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ error: The '?' operator is not supported outside of functions.
Option::<felt252>::Some(0)?
^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: A numeric literal of type core::bool cannot be created.
--> lib.cairo:6:42
const WRONG_TYPE_AND_NOT_LITERAL: bool = 1 + 2;
^

error: A numeric literal of type core::bool cannot be created.
--> lib.cairo:6:46
const WRONG_TYPE_AND_NOT_LITERAL: bool = 1 + 2;
^

error: Trait has no implementation in context: core::traits::Add::<core::bool>.
--> lib.cairo:6:42
const WRONG_TYPE_AND_NOT_LITERAL: bool = 1 + 2;
Expand Down Expand Up @@ -109,11 +99,6 @@ foo
const DEFAULT_VAR: bool = 1;

//! > expected_diagnostics
error: A numeric literal of type core::bool cannot be created.
--> lib.cairo:1:27
const DEFAULT_VAR: bool = 1;
^

error: Mismatched types. The type `core::bool` cannot be created from a numeric literal.
--> lib.cairo:1:27
const DEFAULT_VAR: bool = 1;
Expand All @@ -136,11 +121,6 @@ foo
const B: u8 = -1;

//! > expected_diagnostics
error: The value does not fit within the range of type core::integer::u8.
--> lib.cairo:1:15
const B: u8 = -1;
^^

error: Trait has no implementation in context: core::traits::Neg::<core::integer::u8>.
--> lib.cairo:1:15
const B: u8 = -1;
Expand Down Expand Up @@ -231,47 +211,6 @@ const COMPLEX_STRUCT: ComplexStruct = ComplexStruct {

const CONST_MEMBER: u8 = COMPLEX_STRUCT.a;

//! > semantic_diagnostics
error: The value does not fit within the range of type core::integer::u8.
--> lib.cairo:1:26
const UNSIGNED_VAR: u8 = 256;
^*^

error: The value does not fit within the range of type core::integer::i8.
--> lib.cairo:2:24
const SIGNED_VAR: i8 = 128;
^*^

error: The value does not fit within the range of type core::integer::i8.
--> lib.cairo:5:36
const OUT_OF_RANGE_NEGATIVE1: i8 = -0x81;
^***^

error: The value does not fit within the range of type core::integer::i16.
--> lib.cairo:6:37
const OUT_OF_RANGE_NEGATIVE2: i16 = -0x8001;
^*****^

error: The value does not fit within the range of type core::zeroable::NonZero::<core::integer::u8>.
--> lib.cairo:7:36
const ZERO_NON_ZERO: NonZero<u8> = 0;
^

error: The value does not fit within the range of type core::integer::i8.
--> lib.cairo:9:39
const CALCULATION_WITH_OVERFLOW: i8 = 120 + 10;
^******^

error: This expression is not supported as constant.
--> lib.cairo:10:39
const CALCULATION_WITH_DIVISION: u8 = 120 / 0;
^*****^

error: The value does not fit within the range of type core::zeroable::NonZero::<core::integer::u8>.
--> lib.cairo:28:8
d: 0,
^

//! > expected_diagnostics
error: The value does not fit within the range of type core::integer::u8.
--> lib.cairo:1:26
Expand Down
Loading

0 comments on commit eabc3e0

Please sign in to comment.