mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
Eliminate voided branches only after resolving their bodies' specializations
This commit is contained in:
parent
884843205d
commit
2f7020aa31
3 changed files with 93 additions and 7 deletions
|
@ -1962,3 +1962,41 @@ fn unreachable_void_constructor() {
|
|||
"#
|
||||
)
|
||||
}
|
||||
|
||||
#[mono_test]
|
||||
fn unreachable_branch_is_eliminated_but_produces_lambda_specializations() {
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
provideThunk = \x ->
|
||||
when x is
|
||||
Ok _ ->
|
||||
t1 = \{} -> "t1"
|
||||
t1
|
||||
# During specialization of `main` we specialize this function,
|
||||
# which leads to elimination of this branch, because it is unreachable
|
||||
# (it can only match the uninhabited type `Err []`).
|
||||
#
|
||||
# However, naive elimination of this branch would mean we don't traverse
|
||||
# the branch body. If we don't do so, we will fail to see and specialize `t2`,
|
||||
# which is problematic - while `t2` won't ever be reached in this specialization,
|
||||
# it is still part of the lambda set, and `thunk {}` (in main) will match over
|
||||
# it before calling.
|
||||
#
|
||||
# So, this test verifies that we eliminate this branch, but still specialize
|
||||
# everything we need.
|
||||
Err _ ->
|
||||
t2 = \{} -> "t2"
|
||||
t2
|
||||
|
||||
main =
|
||||
x : Result Str []
|
||||
x = Ok "abc"
|
||||
|
||||
thunk = provideThunk x
|
||||
|
||||
thunk {}
|
||||
"#
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue