Skip to content

Commit

Permalink
Add a diagnostics test. (#6268)
Browse files Browse the repository at this point in the history
  • Loading branch information
liorgold2 authored Aug 24, 2024
1 parent aaad921 commit 444e535
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/cairo-lang-semantic/src/expr/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ cairo_lang_test_utils::test_file_test!(
statements: "statements",
structure: "structure",
while_: "while",
impl_: "impl",
},
test_function_diagnostics
);
Expand Down
69 changes: 69 additions & 0 deletions crates/cairo-lang-semantic/src/expr/test_data/impl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//! > Unknown types in trait/impl methods.

//! > test_runner_name
test_function_diagnostics(expect_diagnostics: true)

//! > function
fn foo() {}

//! > function_name
foo

//! > module_code
trait MyTrait {
fn foo(x: u8, y: T, z: u8) -> u8;
fn bar() -> T;
}

impl MyImpl of MyTrait {
fn foo(x: T, y: u8, z: u16) -> T {}
fn bar() -> u8 {
0
}
}

//! > expected_diagnostics
error: Type not found.
--> lib.cairo:2:22
fn foo(x: u8, y: T, z: u8) -> u8;
^

error: Type not found.
--> lib.cairo:3:17
fn bar() -> T;
^

error: Type not found.
--> lib.cairo:7:15
fn foo(x: T, y: u8, z: u16) -> T {}
^

error: Type not found.
--> lib.cairo:7:36
fn foo(x: T, y: u8, z: u16) -> T {}
^

error: Parameter type of impl function `MyImpl::foo` is incompatible with `MyTrait::foo`. Expected: `core::integer::u8`, actual: `<missing>`.
--> lib.cairo:7:15
fn foo(x: T, y: u8, z: u16) -> T {}
^

error: Parameter type of impl function `MyImpl::foo` is incompatible with `MyTrait::foo`. Expected: `<missing>`, actual: `core::integer::u8`.
--> lib.cairo:7:21
fn foo(x: T, y: u8, z: u16) -> T {}
^^

error: Parameter type of impl function `MyImpl::foo` is incompatible with `MyTrait::foo`. Expected: `core::integer::u8`, actual: `core::integer::u16`.
--> lib.cairo:7:28
fn foo(x: T, y: u8, z: u16) -> T {}
^*^

error: Return type of impl function `MyImpl::foo` is incompatible with `MyTrait::foo`. Expected: `core::integer::u8`, actual: `<missing>`.
--> lib.cairo:7:36
fn foo(x: T, y: u8, z: u16) -> T {}
^

error: Return type of impl function `MyImpl::bar` is incompatible with `MyTrait::bar`. Expected: `<missing>`, actual: `core::integer::u8`.
--> lib.cairo:8:17
fn bar() -> u8 {
^^

0 comments on commit 444e535

Please sign in to comment.