Define inline expects defs in their definition order

When we transform a top-level expect into an inline expect, we collect
all intermediate defs before the expect condition, then layer the defs
back on. Because the layering procedure builds an expression bottom-up,
we must layer on defs in reverse definition order.

Closes #4705
This commit is contained in:
Ayaz Hafiz 2022-12-07 10:54:16 -06:00
parent 935255d06b
commit 42fe19541e
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 18 additions and 1 deletions

View file

@ -2995,7 +2995,7 @@ fn toplevel_expect_to_inline_expect_help(mut loc_expr: Loc<Expr>, has_effects: b
let mut loc_expr = Loc::at(expect_region, expect);
for stored in stack {
for stored in stack.into_iter().rev() {
match stored {
StoredDef::NonRecursive(region, boxed_def) => {
loc_expr = Loc::at(region, Expr::LetNonRec(boxed_def, Box::new(loc_expr)));

View file

@ -2139,3 +2139,20 @@ fn list_one_vs_one_spread_issue_4685() {
"#
)
}
#[mono_test(mode = "test")]
fn issue_4705() {
indoc!(
r###"
interface Test exposes [] imports []
go : {} -> Bool
go = \{} -> Bool.true
expect
input = {}
x = go input
x
"###
)
}