mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Correctly destructure patterns that are assigned to a thunk'd value
Closes #4309
This commit is contained in:
parent
fb926c9884
commit
a68c63f1d1
2 changed files with 61 additions and 15 deletions
|
@ -2604,9 +2604,11 @@ fn from_can_let<'a>(
|
|||
);
|
||||
}
|
||||
|
||||
if let roc_can::expr::Expr::Var(outer_symbol) = def.loc_expr.value {
|
||||
match def.loc_expr.value {
|
||||
roc_can::expr::Expr::Var(outer_symbol) if !procs.is_module_thunk(outer_symbol) => {
|
||||
store_pattern(env, procs, layout_cache, &mono_pattern, outer_symbol, stmt)
|
||||
} else {
|
||||
}
|
||||
_ => {
|
||||
let outer_symbol = env.unique_symbol();
|
||||
stmt = store_pattern(env, procs, layout_cache, &mono_pattern, outer_symbol, stmt);
|
||||
|
||||
|
@ -2621,6 +2623,7 @@ fn from_can_let<'a>(
|
|||
env.arena.alloc(stmt),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// turn record/tag patterns into a when expression, e.g.
|
||||
|
|
|
@ -1982,3 +1982,46 @@ fn str_with_prefix() {
|
|||
RocStr
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn destructure_pattern_assigned_from_thunk_opaque() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
MyCustomType := Str
|
||||
myMsg = @MyCustomType "Hello"
|
||||
|
||||
main =
|
||||
@MyCustomType msg = myMsg
|
||||
|
||||
msg
|
||||
"#
|
||||
),
|
||||
RocStr::from("Hello"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||
fn destructure_pattern_assigned_from_thunk_tag() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [main] to "./platform"
|
||||
|
||||
myMsg = A "hello " "world"
|
||||
|
||||
main =
|
||||
A m1 m2 = myMsg
|
||||
|
||||
Str.concat m1 m2
|
||||
"#
|
||||
),
|
||||
RocStr::from("hello world"),
|
||||
RocStr
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue