Skip to content

Commit

Permalink
tyck: Add testcases mentioned in #677
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Sep 13, 2024
1 parent 3edfcce commit 649c428
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions typecheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,62 @@ mod tests {

assert!(fir.is_ok());
}

#[test]
fn union_with_constant_valid() {
let ast = ast! {
type Nothing;
type NullableInt = int | Nothing;

func g(n: NullableInt) {}

where x = 16;

g(15);
g(x);
g(Nothing);
};

let fir = fir!(ast).type_check();

assert!(fir.is_ok());
}

#[test]
fn union_with_constant_invalid() {
let ast = ast! {
type Nothing;
type NullableInt = 15 | Nothing;

func g(n: NullableInt) {}

where x = 16;

g(15);
g(x);
g(Nothing);
};

let fir = fir!(ast).type_check();

assert!(fir.is_err());
}

#[test]
fn union_primitive_from_ext_fn() {
let ast = ast! {
ext func magic() -> int;

type Nothing;
type NullableInt = int | Nothing;

func g(n: NullableInt) {}

g(magic());
};

let fir = fir!(ast).type_check();

assert!(fir.is_ok());
}
}

0 comments on commit 649c428

Please sign in to comment.