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 14, 2024
1 parent 3edfcce commit e9004f3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
7 changes: 0 additions & 7 deletions error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,6 @@ impl Display for Error {
}
}

#[cfg(feature = "ffi")]
impl std::convert::From<libloading::Error> for Error {
fn from(e: libloading::Error) -> Error {
Error::new(ErrKind::ExternFunc).with_msg(e.to_string())
}
}

impl std::convert::From<std::env::VarError> for Error {
fn from(e: std::env::VarError) -> Self {
Error::new(ErrKind::ExternFunc).with_msg(e.to_string())
Expand Down
4 changes: 1 addition & 3 deletions fir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,9 @@ pub trait Pass<T: Debug, U: Debug, E> {

// FIXME: Add a #[cfg(not(release))] here
// otherwise just return `fir`
fir.map(|fir| {
fir.inspect(|fir| {
Self::post_condition(&fir);

Check failure on line 338 in fir/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> fir/src/lib.rs:338:34 | 338 | Self::post_condition(&fir); | ^^^^ help: change this to: `fir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `-D clippy::needless-borrow` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrow)]`
fir.check();

fir
})
}
}
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 e9004f3

Please sign in to comment.