Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored const evaluation by usage of context. #6977

Merged
merged 1 commit into from
Jan 5, 2025
Merged
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
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
Loading