Merge pull request #4887 from roc-lang/weakening-5

Finish weakening let-bindings
This commit is contained in:
Ayaz 2023-01-17 12:47:12 -06:00 committed by GitHub
commit ed7123ed5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 109 additions and 69 deletions

View file

@ -943,12 +943,14 @@ mod solve_expr {
infer_eq_without_problem(
indoc!(
r#"
foo = Foo
foo0 = Foo
foo1 = Foo
foo2 = Foo
{
x: [foo, Foo],
y: [foo, \x -> Foo x],
z: [foo, \x,y -> Foo x y]
x: [foo0, Foo],
y: [foo1, \x -> Foo x],
z: [foo2, \x,y -> Foo x y]
}
"#
),
@ -2555,10 +2557,10 @@ mod solve_expr {
infer_eq(
indoc!(
r#"
ok : Result I64 *
ok : Result I64 _
ok = Ok 5
err : Result * Str
err : Result _ Str
err = Err "blah"
if 1 > 0 then
@ -3101,7 +3103,6 @@ mod solve_expr {
#[test]
fn rigid_in_letrec_ignored() {
// re-enable when we don't capture local things that don't need to be!
infer_eq_without_problem(
indoc!(
r#"
@ -3109,7 +3110,7 @@ mod solve_expr {
toEmpty : ConsList a -> ConsList a
toEmpty = \_ ->
result : ConsList a
result : ConsList _ # TODO to enable using `a` we need scoped variables
result = Nil
toEmpty result
@ -3132,7 +3133,7 @@ mod solve_expr {
toEmpty : ConsList a -> ConsList a
toEmpty = \_ ->
result : ConsList a
result : ConsList _ # TODO to enable using `a` we need scoped variables
result = Nil
toEmpty result
@ -4353,12 +4354,12 @@ mod solve_expr {
RBTree k v : [Node NodeColor k v (RBTree k v) (RBTree k v), Empty]
# Create an empty dictionary.
empty : RBTree k v
empty =
empty : {} -> RBTree k v
empty = \{} ->
Empty
foo : RBTree I64 I64
foo = empty
foo = empty {}
main : RBTree I64 I64
main =
@ -6598,6 +6599,42 @@ mod solve_expr {
#^^{-1}
main =
alias1 = \x -> id x
# ^^
alias2 = \x -> alias1 x
# ^^^^^^
a : A
a = alias2 (@A {})
# ^^^^^^
a
"#
),
@r###"
A#id(4) : A -[[id(4)]]-> A
Id#id(2) : a -[[] + a:id(2):1]-> a | a has Id
alias1 : a -[[alias1(6)]]-> a | a has Id
alias2 : A -[[alias2(7)]]-> A
"###
)
}
#[test]
fn resolve_lambda_set_weakened_ability_alias() {
infer_queries!(
indoc!(
r#"
app "test" provides [main] to "./platform"
Id has id : a -> a | a has Id
A := {} has [Id {id}]
id = \@A {} -> @A {}
#^^{-1}
main =
# Both alias1, alias2 should get weakened
alias1 = id
# ^^
alias2 = alias1
@ -6612,8 +6649,8 @@ mod solve_expr {
),
@r###"
A#id(4) : A -[[id(4)]]-> A
Id#id(2) : a -[[] + a:id(2):1]-> a | a has Id
alias1 : a -[[] + a:id(2):1]-> a | a has Id
Id#id(2) : A -[[id(4)]]-> A
alias1 : A -[[id(4)]]-> A
alias2 : A -[[id(4)]]-> A
"###
)
@ -6743,8 +6780,8 @@ mod solve_expr {
#^^{-1}
main =
alias = id
# ^^
alias = \x -> id x
# ^^
a : A
a = (alias (@A {})) {}
@ -6756,7 +6793,7 @@ mod solve_expr {
@r#"
A#id(5) : {} -[[id(5)]]-> ({} -[[8]]-> {})
Id#id(3) : a -[[] + a:id(3):1]-> ({} -[[] + a:id(3):2]-> a) | a has Id
alias : {} -[[id(5)]]-> ({} -[[8]]-> {})
alias : {} -[[alias(9)]]-> ({} -[[8]]-> {})
"#
print_only_under_alias: true
)
@ -6991,7 +7028,7 @@ mod solve_expr {
"#
),
@r#"
foo : [Named Str (List a)]* as a
foo : [Named Str (List a)] as a
Named name outerList : [Named Str (List a)] as a
name : Str
outerList : List ([Named Str (List a)] as a)