mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 11:52:19 +00:00
Deduplicate capture niches
This commit is contained in:
parent
91050d9989
commit
3385c708c6
2 changed files with 29 additions and 0 deletions
|
@ -1009,6 +1009,11 @@ impl<'a> LambdaSet<'a> {
|
|||
joined.sort_by(|(lam_and_captures1, _), (lam_and_captures2, _)| {
|
||||
lam_and_captures1.cmp(lam_and_captures2)
|
||||
});
|
||||
// Remove duplicate lambda captures layouts unification can't see as
|
||||
// duplicates, for example [[Thunk {a: Str}, Thunk [A Str]]], each of which are
|
||||
// newtypes over the lambda layout `Thunk Str`.
|
||||
joined.dedup_by_key(|((name, captures), _)| (*name, *captures));
|
||||
|
||||
let (set, set_with_variables): (std::vec::Vec<_>, std::vec::Vec<_>) =
|
||||
joined.into_iter().unzip();
|
||||
|
||||
|
|
|
@ -1628,3 +1628,27 @@ fn lambda_capture_niches_have_captured_function_in_closure() {
|
|||
"#
|
||||
)
|
||||
}
|
||||
|
||||
#[mono_test]
|
||||
fn lambda_set_niche_same_layout_different_constructor() {
|
||||
indoc!(
|
||||
r#"
|
||||
capture : a -> ({} -> Str)
|
||||
capture = \val ->
|
||||
thunk =
|
||||
\{} ->
|
||||
when val is
|
||||
_ -> ""
|
||||
thunk
|
||||
|
||||
x : [True, False]
|
||||
x = True
|
||||
|
||||
fun =
|
||||
when x is
|
||||
True -> capture {a: ""}
|
||||
False -> capture (A "")
|
||||
fun
|
||||
"#
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue