cairo-lang-semantic 2.18.0

Cairo semantic model.
Documentation
//! > Constructor

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
#[cairofmt::skip]
fn foo(a: A) -> A {
    A {
        b: 1_felt252,
        a: 2,
        c: 7,
        a: 3,
        ..d,
        f: 4,
    }
}

//! > function_name
foo

//! > module_code
struct A {
    a: felt252,
    b: (),
}

//! > expected_diagnostics
error[E2041]: Unexpected argument type. Expected: "()", found: "core::felt252".
 --> lib.cairo:8:12
        b: 1_felt252,
           ^^^^^^^^^

error[E2018]: Unknown member.
 --> lib.cairo:10:9
        c: 7,
        ^

error[E2021]: Member specified more than once.
 --> lib.cairo:11:9
        a: 3,
        ^

error[E2022]: The base struct must always be the last argument.
 --> lib.cairo:12:9
        ..d,
        ^^^

error[E2018]: Unknown member.
 --> lib.cairo:13:9
        f: 4,
        ^

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

//! > Blocks, `if`s, and `match`s, don't require semicolon, even not in tail expressions.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo(a: A) {
    a.f;
    a.a::b;
    a.4.4;
    5_felt252.a;
}

//! > function_name
foo

//! > module_code
struct A {
    a: (felt252,),
    b: felt252,
    c: felt252,
}

//! > expected_diagnostics
error[E0007]: Type "test::A" has no member "f"
 --> lib.cairo:7:7
    a.f;
      ^

error[E2085]: Invalid member expression.
 --> lib.cairo:8:7
    a.a::b;
      ^^^^

error[E2085]: Invalid member expression.
 --> lib.cairo:9:7
    a.4.4;
      ^

error[E2085]: Invalid member expression.
 --> lib.cairo:9:9
    a.4.4;
        ^

error[E0007]: Type "core::felt252" has no member "a"
 --> lib.cairo:10:15
    5_felt252.a;
              ^

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

//! > No effect tail struct.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo(a: A) -> A {
    A { a: 4, ..a }
}

//! > function_name
foo

//! > module_code
struct A {
    a: felt252,
}

//! > expected_diagnostics
error[E2023]: Base struct has no effect, all the fields in the struct have already been specified.
 --> lib.cairo:5:15
    A { a: 4, ..a }
              ^^^

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

//! > Member access on unreduced impl associated type.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function_code
fn foo() {}

//! > function_name
foo

//! > module_code
struct S {
    val: felt252,
}

trait T<X> {
    type A;
    fn f(self: @X) -> Self::A;
}

impl I of T<S> {
    type A = S;
    fn f(self: @S) -> S {
        S { val: 0 }
    }
}

fn g<X, impl H: T<X>>(x: @X) -> felt252 {
    H::f(x).val
}

//! > expected_diagnostics
error[E2057]: Type "H::A" has no members.
 --> lib.cairo:18:13
    H::f(x).val
            ^^^