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 23, 2024
1 parent cb7675d commit b045efc
Show file tree
Hide file tree
Showing 9 changed files with 883 additions and 70 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 SingleConstMod {
pub const A: u8 = 1;
}

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

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

#[test]
fn test_use_constant_shadowing() {
use X::A;
use SingleConstMod::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 DoubleConstMod {
pub const A: u8 = 4;
pub const B: u8 = 6;
}

#[test]
fn test_use_use_shadowing() {
use X::A;
use SingleConstMod::A;
assert_eq!(A, 1);
{
use Y::A;
use DoubleConstMod::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 DoubleConstMod::A;
assert_eq!(A, 4);
}
assert_eq!(A, 1);
}

#[test]
fn test_use_let_shadowing() {
use X::A;
use SingleConstMod::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 DoubleConstMod::A;
assert_eq!(A, 4);
}
assert_eq!(A, 1);
}

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

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

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

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

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

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

#[test]
fn test_type_enum_generic_usage() {
use GenericTypeModGenerics::E;
let e = E::A::<u8>(1);
match e {
E::A(val) => assert_eq!(val, 1),
E::B(_) => panic!("Shouldn't get here"),
}
}
10 changes: 9 additions & 1 deletion crates/cairo-lang-semantic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ impl DiagnosticEntry for SemanticDiagnostic {
identifier_name
)
}
SemanticDiagnosticKind::MultipleTypeDefinition(type_name) => {
format!(r#"Multiple definitions of type "{}"."#, type_name)
}
SemanticDiagnosticKind::UnusedType => "Unused type.".into(),

SemanticDiagnosticKind::UnsupportedUseItemInStatement => {
"Unsupported use item in statement.".into()
}
Expand Down Expand Up @@ -899,7 +904,8 @@ impl DiagnosticEntry for SemanticDiagnostic {
| SemanticDiagnosticKind::UnusedImport { .. }
| SemanticDiagnosticKind::CallingShadowedFunction { .. }
| SemanticDiagnosticKind::UnusedConstant
| SemanticDiagnosticKind::UnusedUse => Severity::Warning,
| SemanticDiagnosticKind::UnusedUse
| SemanticDiagnosticKind::UnusedType => Severity::Warning,
SemanticDiagnosticKind::PluginDiagnostic(diag) => diag.severity,
_ => Severity::Error,
}
Expand Down Expand Up @@ -1102,8 +1108,10 @@ pub enum SemanticDiagnosticKind {
UnusedVariable,
UnusedConstant,
UnusedUse,
UnusedType,
MultipleConstantDefinition(SmolStr),
MultipleDefinitionforBinding(SmolStr),
MultipleTypeDefinition(SmolStr),
UnsupportedUseItemInStatement,
ConstGenericParamNotSupported,
NegativeImplsNotEnabled,
Expand Down
Loading

0 comments on commit b045efc

Please sign in to comment.