cairo-lang-semantic 2.18.0

Cairo semantic model.
Documentation
//! > Repeated modifiers for a local variable (first modifier is `mut`).

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {
    let mut ref mut ref ref _a = 3;
}

//! > function_name
foo

//! > expected_diagnostics
error[E2101]: `ref` modifier was specified after another modifier (`mut`). Only a single modifier is allowed.
 --> lib.cairo:2:13
    let mut ref mut ref ref _a = 3;
            ^^^

error[E2101]: `mut` modifier was specified after another modifier (`mut`). Only a single modifier is allowed.
 --> lib.cairo:2:17
    let mut ref mut ref ref _a = 3;
                ^^^

error[E2101]: `ref` modifier was specified after another modifier (`mut`). Only a single modifier is allowed.
 --> lib.cairo:2:21
    let mut ref mut ref ref _a = 3;
                    ^^^

error[E2101]: `ref` modifier was specified after another modifier (`mut`). Only a single modifier is allowed.
 --> lib.cairo:2:25
    let mut ref mut ref ref _a = 3;
                        ^^^

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

//! > Repeated modifiers for a local variable (first modifier is `ref`).

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {
    let ref mut _a = 3;
}

//! > function_name
foo

//! > expected_diagnostics
error[E2101]: `mut` modifier was specified after another modifier (`ref`). Only a single modifier is allowed.
 --> lib.cairo:2:13
    let ref mut _a = 3;
            ^^^

error[E2102]: `ref` is only allowed for function parameters, not for local variables.
 --> lib.cairo:2:17
    let ref mut _a = 3;
                ^^

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

//! > Unsupported ref modifier for a local variable.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {
    let ref _a = 3;
}

//! > function_name
foo

//! > expected_diagnostics
error[E2102]: `ref` is only allowed for function parameters, not for local variables.
 --> lib.cairo:2:13
    let ref _a = 3;
            ^^

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

//! > Variable not found diagnostics

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {
    let _x = not_found;
    let _x = foo;
}

//! > function_name
foo

//! > expected_diagnostics
error[E0006]: Identifier not found.
 --> lib.cairo:2:14
    let _x = not_found;
             ^^^^^^^^^

error[E2005]: Expected variable or constant, found function.
 --> lib.cairo:3:14
    let _x = foo;
             ^^^

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

//! > Type mismatch diagnostics

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {
    let _a: () = 3_felt252;
}

//! > function_name
foo

//! > expected_diagnostics
error[E2041]: Unexpected argument type. Expected: "()", found: "core::felt252".
 --> lib.cairo:2:18
    let _a: () = 3_felt252;
                 ^^^^^^^^^

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

//! > Test let introduce variables into environment, even when diagnostics prevented evaluation.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {
    let (a, b, c) = undefined();
    let [d, e, f] = (a, b, c);
    let (g, h, i) = [d, e, f];
    let (j, k, l, m) = (g, h, i);
    let [n, o, p] = [j, k, l, m];
    let _ignore = n + o + p;
}

//! > function_name
foo

//! > expected_diagnostics
error[E0006]: Function not found.
 --> lib.cairo:2:21
    let (a, b, c) = undefined();
                    ^^^^^^^^^

error[E2103]: Mismatched types: pattern cannot match against type "(<missing>, <missing>, <missing>)".
 --> lib.cairo:3:9
    let [d, e, f] = (a, b, c);
        ^^^^^^^^^

error[E2103]: Mismatched types: pattern cannot match against type "[<missing>; 3]".
 --> lib.cairo:4:9
    let (g, h, i) = [d, e, f];
        ^^^^^^^^^

error[E2107]: Wrong number of tuple elements in pattern. Expected: 3. Got: 4.
 --> lib.cairo:5:9
    let (j, k, l, m) = (g, h, i);
        ^^^^^^^^^^^^

error[E2108]: Wrong number of fixed size array elements in pattern. Expected: 4. Got: 3.
 --> lib.cairo:6:9
    let [n, o, p] = [j, k, l, m];
        ^^^^^^^^^