Merge pull request #4882 from roc-lang/weakening-3

Begin weakening let-bindings to non-function, non-number expressions
This commit is contained in:
Folkert de Vries 2023-01-14 15:32:27 +01:00 committed by GitHub
commit e3a213c0dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 129 additions and 60 deletions

View file

@ -619,22 +619,6 @@ mod solve_expr {
);
}
#[test]
fn concat_different_types() {
infer_eq(
indoc!(
r#"
empty = []
one = List.concat [1] empty
str = List.concat ["blah"] empty
empty
"#
),
"List *",
);
}
#[test]
fn list_of_one_int() {
infer_eq(
@ -3959,11 +3943,11 @@ mod solve_expr {
f : List a -> List a
f = \input ->
# let-polymorphism at work
x : List b
x = []
x : {} -> List b
x = \{} -> []
when List.get input 0 is
Ok val -> List.append x val
Ok val -> List.append (x {}) val
Err _ -> input
f
"#
@ -6688,6 +6672,7 @@ mod solve_expr {
main =
choice : [T, U]
# Should not get generalized
idChoice =
#^^^^^^^^{-1}
when choice is
@ -6701,7 +6686,7 @@ mod solve_expr {
@r###"
A#id(4) : A -[[id(4)]]-> A
idNotAbility : a -[[idNotAbility(5)]]-> a
idChoice : a -[[idNotAbility(5)] + a:id(2):1]-> a | a has Id
idChoice : A -[[id(4), idNotAbility(5)]]-> A
idChoice : A -[[id(4), idNotAbility(5)]]-> A
"###
)
@ -6723,6 +6708,7 @@ mod solve_expr {
main =
choice : [T, U]
# Should not get generalized
idChoice =
#^^^^^^^^{-1}
when choice is
@ -6735,7 +6721,7 @@ mod solve_expr {
),
@r#"
A#id(4) : A -[[id(4)]]-> A
idChoice : a -[[] + a:id(2):1]-> a | a has Id
idChoice : A -[[id(4)]]-> A
idChoice : A -[[id(4)]]-> A
"#
)
@ -6951,7 +6937,7 @@ mod solve_expr {
#^^^^^^^^^^^^^^^^^^^^^^{-1}
"#
),
@r###"[\{} -> {}, \{} -> {}] : List ({}* -[[1, 2]]-> {})"###
@r###"[\{} -> {}, \{} -> {}] : List ({}w_a -[[1, 2]]-> {})"###
)
}
@ -7678,7 +7664,7 @@ mod solve_expr {
A _ C -> ""
"#
),
@r#"x : [A [B]* [C]*]"#
@r#"x : [A [B]w_a [C]w_b]"#
allow_errors: true
);
}
@ -7694,7 +7680,7 @@ mod solve_expr {
_ -> ""
"#
),
@r#"x : { a : [A { b : [B]* }*]* }*"#
@"x : { a : [A { b : [B]w_a }*]w_b }*"
);
}
@ -8598,8 +8584,8 @@ mod solve_expr {
"#
),
@r###"
a : [A Str]*
b : [A Str]*
a : [A Str]w_a
b : [A Str]w_a
"###
);
}
@ -8697,4 +8683,19 @@ mod solve_expr {
@"main : {}* -[[main(0)]]-> { y : [Green, Red]a, z : [Green, Red]a }"
);
}
#[test]
fn weakened_list() {
infer_queries!(
indoc!(
r#"
app "test" provides [main] to "./platform"
main = []
#^^^^{-1}
"#
),
@"main : List w_a"
);
}
}