From 444e535c4ecbdd4b7d498bcab136b8025bdfafa7 Mon Sep 17 00:00:00 2001 From: liorgold2 <38202661+liorgold2@users.noreply.github.com> Date: Sat, 24 Aug 2024 14:48:24 +0300 Subject: [PATCH] Add a diagnostics test. (#6268) --- crates/cairo-lang-semantic/src/expr/test.rs | 1 + .../src/expr/test_data/impl | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 crates/cairo-lang-semantic/src/expr/test_data/impl diff --git a/crates/cairo-lang-semantic/src/expr/test.rs b/crates/cairo-lang-semantic/src/expr/test.rs index b847178e8a5..d7ff09948a1 100644 --- a/crates/cairo-lang-semantic/src/expr/test.rs +++ b/crates/cairo-lang-semantic/src/expr/test.rs @@ -57,6 +57,7 @@ cairo_lang_test_utils::test_file_test!( statements: "statements", structure: "structure", while_: "while", + impl_: "impl", }, test_function_diagnostics ); diff --git a/crates/cairo-lang-semantic/src/expr/test_data/impl b/crates/cairo-lang-semantic/src/expr/test_data/impl new file mode 100644 index 00000000000..2d56056a1ec --- /dev/null +++ b/crates/cairo-lang-semantic/src/expr/test_data/impl @@ -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: ``. + --> 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: ``, 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: ``. + --> 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: ``, actual: `core::integer::u8`. + --> lib.cairo:8:17 + fn bar() -> u8 { + ^^