mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 15:03:46 +00:00
Ensure ability-bound variables are registered in their generalization pool
When we attempt to bind a type argument to an ability in an alias/opaque instantiation, we create a fresh flex var to represent satisfaction of the ability, and then unify the type argument with that flex var. Previously, we did not register this fresh var in the appropriate rank pool. Usually this is not a problem; however, our generalization algorithm is such that we skip adjusting the rank of redundant variables. Redundant variables are those that are in the same unification tree, but are not the root of the unification trees. This means that if such a flex able var becomes the root of a unification tree with the type argument, and the type argument is itself generalized, we will have missed generalization of the argument. The fix is simple - make sure to register the flex able var into the appropriate rank pool. Closes #4408
This commit is contained in:
parent
716c4cb8e4
commit
b43078440f
2 changed files with 28 additions and 5 deletions
|
@ -8220,4 +8220,26 @@ mod solve_expr {
|
|||
"{} -> Task",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generalize_inferred_opaque_variable_bound_to_ability_issue_4408() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [top] to "./platform"
|
||||
|
||||
MDict u := (List u) | u has Eq
|
||||
|
||||
bot : MDict k -> MDict k
|
||||
bot = \@MDict data ->
|
||||
when {} is
|
||||
{} -> @MDict data
|
||||
|
||||
top : MDict v -> MDict v
|
||||
top = \x -> bot x
|
||||
"#
|
||||
),
|
||||
"MDict v -> MDict v | v has Eq",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue