mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
Implement weakening of variables introduced in branch patterns
Variables introduced in branch patterns should never be generalized in the new weakening model. This implements that. The strategy is: - when we have a let-binding that should be weakened, do not introduce its bound variables in a new (higher) rank - instead, introduce them at the current rank, and also solve the let-binding at the current rank - if any of those variables should then be generalized relative to the current rank, they will be so when the current rank is popped and generalized
This commit is contained in:
parent
7febddd1ea
commit
058644aa96
3 changed files with 53 additions and 44 deletions
|
@ -8674,4 +8674,27 @@ mod solve_expr {
|
|||
@"main : (a -[[]]-> b) -[[main(0)]]-> (a -[[y(2) (a -[[]]-> b)]]-> b)"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn when_branch_variables_not_generalized() {
|
||||
infer_queries!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
main = \{} -> when Red is
|
||||
#^^^^{-1}
|
||||
x ->
|
||||
y : [Red]_
|
||||
y = x
|
||||
|
||||
z : [Red, Green]_
|
||||
z = x
|
||||
|
||||
{y, z}
|
||||
"#
|
||||
),
|
||||
@"main : {}* -[[main(0)]]-> { y : [Green, Red]a, z : [Green, Red]a }"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue