From e9004f3e213c3b97b0461b24cfa513ade18e036a Mon Sep 17 00:00:00 2001 From: Arthur Cohen Date: Fri, 13 Sep 2024 19:10:31 +0200 Subject: [PATCH] tyck: Add testcases mentioned in #677 --- error/src/lib.rs | 7 ------ fir/src/lib.rs | 4 +-- typecheck/src/lib.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/error/src/lib.rs b/error/src/lib.rs index fc731aa2..8ab18fcd 100644 --- a/error/src/lib.rs +++ b/error/src/lib.rs @@ -317,13 +317,6 @@ impl Display for Error { } } -#[cfg(feature = "ffi")] -impl std::convert::From for Error { - fn from(e: libloading::Error) -> Error { - Error::new(ErrKind::ExternFunc).with_msg(e.to_string()) - } -} - impl std::convert::From for Error { fn from(e: std::env::VarError) -> Self { Error::new(ErrKind::ExternFunc).with_msg(e.to_string()) diff --git a/fir/src/lib.rs b/fir/src/lib.rs index 34dcf67c..fc6f3b27 100644 --- a/fir/src/lib.rs +++ b/fir/src/lib.rs @@ -334,11 +334,9 @@ pub trait Pass { // FIXME: Add a #[cfg(not(release))] here // otherwise just return `fir` - fir.map(|fir| { + fir.inspect(|fir| { Self::post_condition(&fir); fir.check(); - - fir }) } } diff --git a/typecheck/src/lib.rs b/typecheck/src/lib.rs index 9f6dc17d..e32602f7 100644 --- a/typecheck/src/lib.rs +++ b/typecheck/src/lib.rs @@ -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()); + } }