//! > Test assignment.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function_code
fn foo(p: felt252) {
p = 7;
a = 1 + 2;
let b = 1;
let _c: felt252 = (b = 5);
let mut x = 1;
x = true;
}
//! > function_name
foo
//! > module_code
extern type MyType;
//! > expected_diagnostics
error[E2083]: Cannot assign to an immutable variable.
--> lib.cairo:3:5
p = 7;
^^^^^
error[E0006]: Identifier not found.
--> lib.cairo:4:5
a = 1 + 2;
^
error[E2084]: Invalid left-hand side of assignment.
--> lib.cairo:4:5
a = 1 + 2;
^
error[E2083]: Cannot assign to an immutable variable.
--> lib.cairo:6:24
let _c: felt252 = (b = 5);
^^^^^
error[E2041]: Unexpected argument type. Expected: "core::felt252", found: "()".
--> lib.cairo:6:23
let _c: felt252 = (b = 5);
^^^^^^^
//! > ==========================================================================
//! > Test a valid let statement with a string literal.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: false)
//! > function_code
fn foo() {
let _x: ByteArray = "error";
}
//! > function_name
foo
//! > expected_diagnostics
//! > ==========================================================================
//! > Test type mismatch of a string literal in a let statement.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function_code
fn foo() {
let _x: felt252 = "error";
}
//! > function_name
foo
//! > expected_diagnostics
error[E2311]: Mismatched types. The type `core::felt252` cannot be created from a string literal.
--> lib.cairo:2:23
let _x: felt252 = "error";
^^^^^^^
//! > ==========================================================================
//! > Test a valid let statement with a numeric literal.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: false)
//! > function_code
fn foo() {
let _x: felt252 = 252;
}
//! > function_name
foo
//! > expected_diagnostics
//! > ==========================================================================
//! > Test type mismatch of a numeric literal in a let statement.
//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)
//! > function_code
fn foo() {
let _x: ByteArray = 252;
}
//! > function_name
foo
//! > expected_diagnostics
error[E2311]: Mismatched types. The type `core::byte_array::ByteArray` cannot be created from a numeric literal.
--> lib.cairo:2:25
let _x: ByteArray = 252;
^^^