mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Don't skip closure captures when fixing them
This commit is contained in:
parent
8e3c1597c3
commit
be30e470a8
3 changed files with 67 additions and 5 deletions
|
@ -1051,14 +1051,13 @@ fn fix_values_captured_in_closure_expr(
|
||||||
debug_assert!(!captures.is_empty());
|
debug_assert!(!captures.is_empty());
|
||||||
captured_symbols.extend(captures);
|
captured_symbols.extend(captures);
|
||||||
captured_symbols.swap_remove(i);
|
captured_symbols.swap_remove(i);
|
||||||
// Jump two, because the next element is now one of the newly-added captures,
|
|
||||||
// which we don't need to check.
|
|
||||||
i += 2;
|
|
||||||
|
|
||||||
added_captures = true;
|
added_captures = true;
|
||||||
} else {
|
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always jump one, because the current element either does not have captures or
|
||||||
|
// is now one of the newly-added captures, which we don't need to check.
|
||||||
|
i += 1;
|
||||||
}
|
}
|
||||||
if added_captures {
|
if added_captures {
|
||||||
// Re-sort, since we've added new captures.
|
// Re-sort, since we've added new captures.
|
||||||
|
|
37
crates/compiler/test_mono/generated/issue_6174.txt
Normal file
37
crates/compiler/test_mono/generated/issue_6174.txt
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
procedure Bool.1 ():
|
||||||
|
let Bool.23 : Int1 = false;
|
||||||
|
ret Bool.23;
|
||||||
|
|
||||||
|
procedure Test.2 (Test.11, Test.1):
|
||||||
|
if Test.1 then
|
||||||
|
let Test.29 : I64 = 0i64;
|
||||||
|
let Test.28 : [C {}, C I64] = TagId(1) Test.29;
|
||||||
|
ret Test.28;
|
||||||
|
else
|
||||||
|
let Test.27 : {} = Struct {};
|
||||||
|
let Test.26 : [C {}, C I64] = TagId(0) Test.27;
|
||||||
|
ret Test.26;
|
||||||
|
|
||||||
|
procedure Test.3 (Test.12, Test.1):
|
||||||
|
if Test.1 then
|
||||||
|
let Test.23 : I64 = 0i64;
|
||||||
|
let Test.22 : [C {}, C I64] = TagId(1) Test.23;
|
||||||
|
ret Test.22;
|
||||||
|
else
|
||||||
|
let Test.21 : {} = Struct {};
|
||||||
|
let Test.20 : [C {}, C I64] = TagId(0) Test.21;
|
||||||
|
ret Test.20;
|
||||||
|
|
||||||
|
procedure Test.4 (Test.13, Test.1):
|
||||||
|
let Test.25 : {} = Struct {};
|
||||||
|
let Test.17 : [C {}, C I64] = CallByName Test.2 Test.25 Test.1;
|
||||||
|
let Test.19 : {} = Struct {};
|
||||||
|
let Test.18 : [C {}, C I64] = CallByName Test.3 Test.19 Test.1;
|
||||||
|
let Test.16 : List [C {}, C I64] = Array [Test.17, Test.18];
|
||||||
|
ret Test.16;
|
||||||
|
|
||||||
|
procedure Test.0 ():
|
||||||
|
let Test.1 : Int1 = CallByName Bool.1;
|
||||||
|
let Test.15 : {} = Struct {};
|
||||||
|
let Test.14 : List [C {}, C I64] = CallByName Test.4 Test.15 Test.1;
|
||||||
|
ret Test.14;
|
|
@ -3474,3 +3474,29 @@ fn issue_5513() {
|
||||||
"
|
"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[mono_test]
|
||||||
|
fn issue_6174() {
|
||||||
|
indoc!(
|
||||||
|
r"
|
||||||
|
g = Bool.false
|
||||||
|
|
||||||
|
a = \_ ->
|
||||||
|
if g then
|
||||||
|
Ok 0
|
||||||
|
else
|
||||||
|
Err NoNumber
|
||||||
|
|
||||||
|
b = \_ ->
|
||||||
|
if g then
|
||||||
|
Ok 0
|
||||||
|
else
|
||||||
|
Err NoNumber
|
||||||
|
|
||||||
|
c = \_ ->
|
||||||
|
[a {}, b {}]
|
||||||
|
|
||||||
|
c {}
|
||||||
|
"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue