Fix return type of List.first

This commit is contained in:
Richard Feldman 2020-06-24 23:52:54 -04:00
parent 2332650785
commit 5cec577427
2 changed files with 16 additions and 6 deletions

View file

@ -525,16 +525,21 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
Symbol::LIST_GET,
unique_function(
vec![list_type(UVAR1, TVAR1), int_type(UVAR2)],
result_type(UVAR3, flex(TVAR1), lift(UVAR4, index_out_of_bounds.clone())),
result_type(UVAR3, flex(TVAR1), lift(UVAR4, index_out_of_bounds)),
),
);
// first : List elem -> Result elem [ OutOfBounds ]*
// first : List elem -> Result elem [ ListWasEmpty ]*
let list_was_empty = SolvedType::TagUnion(
vec![(TagName::Global("ListWasEmpty".into()), vec![])],
Box::new(SolvedType::Wildcard),
);
add_type(
Symbol::LIST_FIRST,
unique_function(
vec![list_type(UVAR1, TVAR1)],
result_type(UVAR3, flex(TVAR1), lift(UVAR4, index_out_of_bounds)),
result_type(UVAR3, flex(TVAR1), lift(UVAR4, list_was_empty)),
),
);