Merge remote-tracking branch 'origin/trunk' into i2453

This commit is contained in:
Folkert 2022-08-11 10:44:26 +02:00
commit 5b10ebeeb7
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
13 changed files with 579 additions and 125 deletions

View file

@ -3812,3 +3812,18 @@ fn when_on_u128() {
i64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn condition_polymorphic_num_becomes_float() {
assert_evals_to!(
indoc!(
r#"
x = if True then 2 else 3
x * 5f32
"#
),
10.,
f32
);
}

View file

@ -3705,3 +3705,136 @@ fn runtime_error_when_degenerate_pattern_reached() {
true // allow errors
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn recursive_lambda_set_issue_3444() {
assert_evals_to!(
indoc!(
r#"
combine = \f, g -> \x -> g (f x)
const = \x -> (\_y -> x)
list = [const "a", const "b", const "c"]
res : Str -> Str
res = List.walk list (const "z") (\c1, c2 -> combine c1 c2)
res "hello"
"#
),
RocStr::from("c"),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn recursive_lambda_set_toplevel_issue_3444() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
combine = \f, g -> \x -> g (f x)
const = \x -> (\_y -> x)
list = [const "a", const "b", const "c"]
res : Str -> Str
res = List.walk list (const "z") (\c1, c2 -> combine c1 c2)
main = res "hello"
"#
),
RocStr::from("c"),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn recursive_lambda_set_issue_3444_inferred() {
assert_evals_to!(
indoc!(
r#"
combine = \f, g -> \x -> g (f x)
const = \x -> (\_y -> x)
list = [const "a", const "b", const "c"]
res = List.walk list (const "z") (\c1, c2 -> combine c1 c2)
res "hello"
"#
),
RocStr::from("c"),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn compose_recursive_lambda_set_productive_toplevel() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
compose = \f, g -> \x -> g (f x)
identity = \x -> x
exclaim = \s -> "\(s)!"
whisper = \s -> "(\(s))"
main =
res: Str -> Str
res = List.walk [ exclaim, whisper ] identity compose
res "hello"
"#
),
RocStr::from("(hello!)"),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn compose_recursive_lambda_set_productive_nested() {
assert_evals_to!(
indoc!(
r#"
compose = \f, g -> \x -> g (f x)
identity = \x -> x
exclaim = \s -> "\(s)!"
whisper = \s -> "(\(s))"
res: Str -> Str
res = List.walk [ exclaim, whisper ] identity compose
res "hello"
"#
),
RocStr::from("(hello!)"),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn compose_recursive_lambda_set_productive_inferred() {
assert_evals_to!(
indoc!(
r#"
compose = \f, g -> \x -> g (f x)
identity = \x -> x
exclaim = \s -> "\(s)!"
whisper = \s -> "(\(s))"
res = List.walk [ exclaim, whisper ] identity compose
res "hello"
"#
),
RocStr::from("(hello!)"),
RocStr
);
}

View file

@ -1913,3 +1913,23 @@ fn issue_3653_recursion_pointer_in_naked_opaque_localized() {
RocStr
)
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn issue_2165_recursive_tag_destructure() {
assert_evals_to!(
indoc!(
r#"
SomeTag : [ Ctor { rec : List SomeTag } ]
x : SomeTag
x = Ctor { rec: [] }
when x is
Ctor { rec } -> Num.toStr (List.len rec)
"#
),
RocStr::from("0"),
RocStr
)
}