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:
Ayaz Hafiz 2023-01-11 14:20:47 -06:00
parent 7febddd1ea
commit 058644aa96
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 53 additions and 44 deletions

View file

@ -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 }"
);
}
}