Skip to content

Commit

Permalink
statement types in resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomer-StarkWare committed Sep 25, 2024
1 parent cb7675d commit df7c8aa
Show file tree
Hide file tree
Showing 9 changed files with 883 additions and 73 deletions.
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"),
}
}
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

0 comments on commit df7c8aa

Please sign in to comment.