//! > Test expansion of consteval_int!
//! > test_runner_name
test_expand_expr(expect_diagnostics: warnings_only)
//! > expr_code
let simple = consteval_int!(4 + 5);
let complex = consteval_int!(23 + 4 * 5 + (4 + 5) / 2);
let temp_overflow = consteval_int!(255 + 1 - 1);
//! > expanded_code
simple: 9
complex: 47
temp_overflow: 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:14
let simple = consteval_int!(4 + 5);
^^^^^^^^^^^^^^^^^^^^^
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:3:15
let complex = consteval_int!(23 + 4 * 5 + (4 + 5) / 2);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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:4:21
let temp_overflow = consteval_int!(255 + 1 - 1);
^^^^^^^^^^^^^^^^^^^^^^^^^^^
//! > ==========================================================================
//! > Test expansion of array macro
//! > test_runner_name
test_expand_expr(expect_diagnostics: true)
//! > expr_code
let full = array![1, 2, 3];
let empty = array![];
//! > expanded_code
full: {
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__
}
empty: {
let mut __array_builder_macro_result__ = core::array::ArrayTrait::new();
__array_builder_macro_result__
}
//! > diagnostics
error[E2314]: Type annotations needed. Failed to infer ?7.
--> lib.cairo:3:13
let empty = array![];
^^^^^^^^
//! > ==========================================================================
//! > Test expansion of panic macro
//! > test_runner_name
test_expand_expr(expect_diagnostics: true)
//! > expr_code
let no_args = panic!();
let short_string = panic!("0123456");
let exactly_31_bytes = panic!("0123456789012345678901234567890");
let more_than_31_bytes = panic!("01234567890123456789012345678901234");
let bad_format = panic!("bad_format(})");
//! > expanded_code
no_args: core::panics::panic_with_byte_array(@"")
short_string: core::panics::panic_with_byte_array(@"0123456")
exactly_31_bytes: core::panics::panic_with_byte_array(@"0123456789012345678901234567890")
more_than_31_bytes: core::panics::panic_with_byte_array(@"01234567890123456789012345678901234")
bad_format: {
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:6:25
let bad_format = panic!("bad_format(})");
^^^^^^^^^^^^^^^
//! > ==========================================================================
//! > Test expansion of user-defined macros
//! > test_runner_name
test_expand_expr(expect_diagnostics: false)
//! > module_code
#[feature("user_defined_inline_macros")]
macro plus_lit {
(+) => { 7 };
}
#[feature("user_defined_inline_macros")]
macro keep_plus {
($a:ident + $b:ident) => { $a + $b };
}
//! > function_body
let x = 1_felt252;
let y = 2_felt252;
//! > expr_code
let plus_as_literal_token = plus_lit!(+);
let literal_token_between_captures = keep_plus!(x + y);
//! > expanded_code
plus_as_literal_token: 7
literal_token_between_captures: x+ y
//! > diagnostics
//! > ==========================================================================
//! > Test macro calls that are not expanded due to errors.
//! > test_runner_name
test_expand_expr(expect_diagnostics: true)
//! > module_code
#[feature("user_defined_inline_macros")]
macro take_ident {
($x:ident) => { 0 };
}
//! > expr_code
let inner_parse_error = array![format!];
let bare_dollar_matches_no_ident_rule = take_ident!($);
let missing_token = array![1, 2;
//! > expanded_code
inner_parse_error: array![format!]
bare_dollar_matches_no_ident_rule: take_ident!($)
missing_token: array![1, 2;
//! > diagnostics
error[E1001]: Missing token ']'.
--> lib.cairo:8:33
let missing_token = array![1, 2;
^
error[E1001]: Missing token ';'.
--> lib.cairo:8:33
let missing_token = array![1, 2;
^
error[E2200]: Plugin diagnostic: Macro cannot be parsed as legacy macro. Expected an argument list wrapped in either parentheses, brackets, or braces.
--> lib.cairo:6:25
let inner_parse_error = array![format!];
^^^^^^^^^^^^^^^
error[E2158]: No matching rule found in inline macro `take_ident`.
--> lib.cairo:7:41
let bare_dollar_matches_no_ident_rule = take_ident!($);
^^^^^^^^^^^^^^