Skip to content

Commit

Permalink
feat: Treat a pattern matched type as if it exists even on type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Mar 24, 2018
1 parent a0ecfd2 commit 42059db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
20 changes: 15 additions & 5 deletions check/src/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,9 @@ impl<'a> Typecheck<'a> {
let field_type = actual_type
.type_field_iter()
.find(|field| field.name.name_eq(&name));
match field_type {

let alias;
let alias = match field_type {
Some(field_type) => {
// This forces refresh_type to remap the name a type was given
// in this module to its actual name
Expand All @@ -1514,13 +1516,21 @@ impl<'a> Typecheck<'a> {
.metadata
.insert(field_type.typ.name.clone(), meta);
}

self.stack_type(name, &field_type.typ);
&field_type.typ
}
None => {
self.error(span, TypeError::UndefinedField(match_type.clone(), name));
self.error(
span,
TypeError::UndefinedField(match_type.clone(), name.clone()),
);
// We still define the type so that any uses later on in the program
// won't error on UndefinedType
alias = Alias::new(name.clone(), self.type_cache.hole());
&alias
}
}
};

self.stack_type(name, &alias);
}

if let Some(ref implicit_import) = *implicit_import {
Expand Down
13 changes: 13 additions & 0 deletions check/tests/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ Test "" 2
assert_err!(result, UndefinedVariable(..));
}

#[test]
fn undefined_type_in_pattern_match_triggers_only_one_error() {
let _ = env_logger::try_init();
let text = r#"
let { Test } = {}
type Test2 = Test
()
"#;
let result = support::typecheck(text);

assert_err!(result, UndefinedField(..));
}

#[test]
fn mutually_recursive_types_error() {
let _ = env_logger::try_init();
Expand Down

0 comments on commit 42059db

Please sign in to comment.