don't create IsOpenType constraint for obvious non-types

This commit is contained in:
Folkert 2022-03-19 21:39:07 +01:00
parent f5ebc5bec9
commit 6aaef49aa7
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -172,18 +172,23 @@ pub fn constrain_pattern(
// A -> ""
// _ -> ""
// so, we know that "x" (in this case, a tag union) must be open.
if could_be_a_tag_union(expected.get_type_ref()) {
state
.constraints
.push(constraints.is_open_type(expected.get_type()));
}
}
UnsupportedPattern(_) | MalformedPattern(_, _) | OpaqueNotInScope(..) => {
// Erroneous patterns don't add any constraints.
}
Identifier(symbol) | Shadowed(_, _, symbol) => {
if could_be_a_tag_union(expected.get_type_ref()) {
state
.constraints
.push(constraints.is_open_type(expected.get_type_ref().clone()));
}
state.headers.insert(
*symbol,
Loc {
@ -552,3 +557,7 @@ pub fn constrain_pattern(
}
}
}
fn could_be_a_tag_union(typ: &Type) -> bool {
!matches!(typ, Type::Apply(..) | Type::Function(..) | Type::Record(..))
}