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 -> "" // A -> ""
// _ -> "" // _ -> ""
// so, we know that "x" (in this case, a tag union) must be open. // so, we know that "x" (in this case, a tag union) must be open.
state if could_be_a_tag_union(expected.get_type_ref()) {
.constraints state
.push(constraints.is_open_type(expected.get_type())); .constraints
.push(constraints.is_open_type(expected.get_type()));
}
} }
UnsupportedPattern(_) | MalformedPattern(_, _) | OpaqueNotInScope(..) => { UnsupportedPattern(_) | MalformedPattern(_, _) | OpaqueNotInScope(..) => {
// Erroneous patterns don't add any constraints. // Erroneous patterns don't add any constraints.
} }
Identifier(symbol) | Shadowed(_, _, symbol) => { Identifier(symbol) | Shadowed(_, _, symbol) => {
state if could_be_a_tag_union(expected.get_type_ref()) {
.constraints state
.push(constraints.is_open_type(expected.get_type_ref().clone())); .constraints
.push(constraints.is_open_type(expected.get_type_ref().clone()));
}
state.headers.insert( state.headers.insert(
*symbol, *symbol,
Loc { 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(..))
}