cairo-lang-semantic 2.18.0

Cairo semantic model.
Documentation
//! > Test expansion of consteval_int! simple usage

//! > test_runner_name
test_expand_expr(expect_diagnostics: warnings_only)

//! > expr_code
consteval_int!(4 + 5)

//! > expanded_code
9

//! > diagnostics
warning[E2200]: Plugin diagnostic: Usage of deprecated macro `consteval_int` with no `#[feature("deprecated-consteval-int-macro")]` attribute. Note: Use simple calculations instead, as these are supported in const context.
 --> lib.cairo:2:1
consteval_int!(4 + 5)
^^^^^^^^^^^^^^^^^^^^^

//! > ==========================================================================

//! > Test expansion of consteval_int! complex usage

//! > test_runner_name
test_expand_expr(expect_diagnostics: warnings_only)

//! > expr_code
consteval_int!(23 + 4 * 5 + (4 + 5) / 2)

//! > expanded_code
47

//! > diagnostics
warning[E2200]: Plugin diagnostic: Usage of deprecated macro `consteval_int` with no `#[feature("deprecated-consteval-int-macro")]` attribute. Note: Use simple calculations instead, as these are supported in const context.
 --> lib.cairo:2:1
consteval_int!(23 + 4 * 5 + (4 + 5) / 2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

//! > ==========================================================================

//! > Test expansion of consteval_int! handle temporary overflow

//! > test_runner_name
test_expand_expr(expect_diagnostics: warnings_only)

//! > expr_code
consteval_int!(255 + 1 - 1)

//! > expanded_code
255

//! > diagnostics
warning[E2200]: Plugin diagnostic: Usage of deprecated macro `consteval_int` with no `#[feature("deprecated-consteval-int-macro")]` attribute. Note: Use simple calculations instead, as these are supported in const context.
 --> lib.cairo:2:1
consteval_int!(255 + 1 - 1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^

//! > ==========================================================================

//! > Test expansion of array macro

//! > test_runner_name
test_expand_expr(expect_diagnostics: false)

//! > expr_code
array![1, 2, 3]

//! > expanded_code
{
    let mut __array_builder_macro_result__ = core::array::ArrayTrait::new();
    core::array::ArrayTrait::append(ref __array_builder_macro_result__,1);
    core::array::ArrayTrait::append(ref __array_builder_macro_result__,2);
    core::array::ArrayTrait::append(ref __array_builder_macro_result__,3);
    __array_builder_macro_result__
}

//! > diagnostics

//! > ==========================================================================

//! > Test expansion of array macro empty

//! > test_runner_name
test_expand_expr(expect_diagnostics: true)

//! > expr_code
array![]

//! > expanded_code
{
    let mut __array_builder_macro_result__ = core::array::ArrayTrait::new();
    __array_builder_macro_result__
}

//! > diagnostics
error[E2314]: Type annotations needed. Failed to infer ?0.
 --> lib.cairo:2:1
array![]
^^^^^^^^

//! > ==========================================================================

//! > Test expansion of panic macro with no arguments

//! > test_runner_name
test_expand_expr(expect_diagnostics: false)

//! > expr_code
panic!()

//! > expanded_code
core::panics::panic_with_byte_array(@"")

//! > diagnostics

//! > ==========================================================================

//! > Test expansion of panic macro with a simple short string

//! > test_runner_name
test_expand_expr(expect_diagnostics: false)

//! > expr_code
panic!("0123456")

//! > expanded_code
core::panics::panic_with_byte_array(@"0123456")

//! > diagnostics

//! > ==========================================================================

//! > Test expansion of panic macro with a 31 byte string.

//! > test_runner_name
test_expand_expr(expect_diagnostics: false)

//! > expr_code
panic!("0123456789012345678901234567890")

//! > expanded_code
core::panics::panic_with_byte_array(@"0123456789012345678901234567890")

//! > diagnostics

//! > ==========================================================================

//! > Test expansion of panic macro with a simple 35 bytes string.

//! > test_runner_name
test_expand_expr(expect_diagnostics: false)

//! > expr_code
panic!("01234567890123456789012345678901234")

//! > expanded_code
core::panics::panic_with_byte_array(@"01234567890123456789012345678901234")

//! > diagnostics

//! > ==========================================================================

//! > Test expansion of panic macro with args

//! > test_runner_name
test_expand_expr(expect_diagnostics: true)

//! > expr_code
panic!("bad_format(})")

//! > expanded_code
{
    let mut __formatter_for_panic_macro__: core::fmt::Formatter = core::traits::Default::default();
    core::result::ResultTrait::<(), core::fmt::Error>::unwrap(
write!(__formatter_for_panic_macro__, "bad_format(})")
    );
    core::panics::panic_with_byte_array(@__formatter_for_panic_macro__.buffer)
}

//! > diagnostics
error[E2200]: Plugin diagnostic: Closing `}` without a matching `{`.
 --> lib.cairo:2:8
panic!("bad_format(})")
       ^^^^^^^^^^^^^^^

//! > ==========================================================================

//! > Test expansion of macro with inner parse errors.

//! > test_runner_name
test_expand_expr(expect_diagnostics: true)

//! > expr_code
array![format!]

//! > expanded_code
array![format!]

//! > diagnostics
error[E2200]: Plugin diagnostic: Macro cannot be parsed as legacy macro. Expected an argument list wrapped in either parentheses, brackets, or braces.
 --> lib.cairo:2:1
array![format!]
^^^^^^^^^^^^^^^