Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statement types in resolver #6408

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 65 additions & 11 deletions corelib/src/test/language_features/block_level_items_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@ fn test_global_const_to_let_shadowing() {
assert_eq!(A, 4);
}

pub mod X {
pub mod single_const {
pub const A: u8 = 1;
}

#[test]
fn test_use_usage() {
use X::A;
use single_const::A;
assert_eq!(A, 1);
}

#[test]
fn test_use_usage_with_alias() {
use X::A as B;
use single_const::A as B;
assert_eq!(B, 1);
}

#[test]
fn test_use_constant_shadowing() {
use X::A;
use single_const::A;
assert_eq!(A, 1);
{
const A: u8 = 4;
Expand All @@ -73,17 +73,17 @@ fn test_use_constant_shadowing() {
assert_eq!(A, 1);
}

pub mod Y {
pub mod double_const {
pub const A: u8 = 4;
pub const B: u8 = 6;
}

#[test]
fn test_use_use_shadowing() {
use X::A;
use single_const::A;
assert_eq!(A, 1);
{
use Y::A;
use double_const::A;
assert_eq!(A, 4);
}
assert_eq!(A, 1);
Expand All @@ -94,15 +94,15 @@ fn test_const_use_shadowing() {
const A: u8 = 1;
assert_eq!(A, 1);
{
use Y::A;
use double_const::A;
assert_eq!(A, 4);
}
assert_eq!(A, 1);
}

#[test]
fn test_use_let_shadowing() {
use X::A;
use single_const::A;
assert_eq!(A, 1);
{
let A = 4;
Expand All @@ -116,15 +116,69 @@ fn test_let_use_shadowing() {
let A = 1;
assert_eq!(A, 1);
{
use Y::A;
use double_const::A;
assert_eq!(A, 4);
}
assert_eq!(A, 1);
}

#[test]
fn test_multiple_use() {
use Y::{A, B};
use double_const::{A, B};
assert_eq!(A, 4);
assert_eq!(B, 6);
}

pub mod generic_type {
pub struct S {
pub x: u8,
}
pub enum E {
A: u8,
B: u16,
}
}

#[test]
fn test_type_struct_usage() {
use generic_type::S;
let s = S { x: 1 };
assert_eq!(s.x, 1);
}

#[test]
fn test_type_enum_usage() {
use generic_type::E;
let e = E::A(1);
match e {
E::A(val) => assert_eq!(val, 1),
E::B(_) => panic!("Shouldn't get here"),
}
}

pub mod generic_type_generics {
pub struct S<T> {
pub x: T,
}
pub enum E<T> {
A: T,
B: u16,
}
}

#[test]
fn test_type_struct_generic_usage() {
use generic_type_generics::S;
let s = S::<u8> { x: 1 };
assert_eq!(s.x, 1);
}

#[test]
fn test_type_enum_generic_usage() {
use generic_type_generics::E;
let e = E::A::<u8>(1);
match e {
E::A(val) => assert_eq!(val, 1),
E::B(_) => panic!("Shouldn't get here"),
}
}
1 change: 1 addition & 0 deletions crates/cairo-lang-lowering/src/test_data/members
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! > test_runner_name
test_function_lowering(expect_diagnostics: false)


//! > function
fn foo(ref a: A) {
a.f = 5;
Expand Down
4 changes: 4 additions & 0 deletions crates/cairo-lang-semantic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ impl DiagnosticEntry for SemanticDiagnostic {
identifier_name
)
}
SemanticDiagnosticKind::MultipleGenericItemDefinition(type_name) => {
format!(r#"Multiple definitions of an item "{}"."#, type_name)
}
SemanticDiagnosticKind::UnsupportedUseItemInStatement => {
"Unsupported use item in statement.".into()
}
Expand Down Expand Up @@ -1104,6 +1107,7 @@ pub enum SemanticDiagnosticKind {
UnusedUse,
MultipleConstantDefinition(SmolStr),
MultipleDefinitionforBinding(SmolStr),
MultipleGenericItemDefinition(SmolStr),
UnsupportedUseItemInStatement,
ConstGenericParamNotSupported,
NegativeImplsNotEnabled,
Expand Down
Loading