Skip to content

Commit

Permalink
feat(check): Avoid generating more errors from a type that could not …
Browse files Browse the repository at this point in the history
…be imported
  • Loading branch information
Marwes committed Nov 8, 2019
1 parent 27c73f3 commit 752e2bc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions base/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,12 @@ pub trait TypeExt: Deref<Target = Type<<Self as TypeExt>::Id, Self>> + Clone + S
Self: fmt::Display,
Self::Id: fmt::Display,
{
// If the alias was just hiding an error then any application is also an error as we have
// no way of knowing how many arguments it should take
if let Type::Error = &**self {
return Some((self.clone(), &[]));
}

let typ = if params.len() == args.len() {
Cow::Borrowed(self)
} else {
Expand Down
2 changes: 1 addition & 1 deletion check/src/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ impl<'a> Typecheck<'a> {
);
// We still define the type so that any uses later on in the program
// won't error on UndefinedType
let hole = self.subs.hole();
let hole = self.subs.error();
alias = self.new_alias(name.clone(), Vec::new(), hole);
&alias
}
Expand Down
35 changes: 35 additions & 0 deletions check/tests/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,38 @@ match reverse (Cons 1 Nil) with
"#,
Unification(..)
}

test_check_err! {
missing_type_field,
r#"
type Alternative f = {
empty : forall a . f a,
}
rec
type Arr r a b = a -> Eff r b
type Eff r a =
| Pure a
| Impure : forall x . r x -> Arr r x a -> Eff r a
in
let any x = any x
let { HttpEffect } = ()
let alt =
type Alt r a =
| Empty
.. r
let alternative : Alternative (Eff [| alt : Alt | r |]) = {
empty = any (),
}
{ alternative }
let alternative : Alternative (Eff (HttpEffect r)) = alt.alternative
()
"#,
UndefinedField(..)
}

0 comments on commit 752e2bc

Please sign in to comment.