diff --git a/crates/compiler/mono/src/ir.rs b/crates/compiler/mono/src/ir.rs index 4bb5c799ed..22b1f4dfd5 100644 --- a/crates/compiler/mono/src/ir.rs +++ b/crates/compiler/mono/src/ir.rs @@ -2604,22 +2604,25 @@ fn from_can_let<'a>( ); } - if let roc_can::expr::Expr::Var(outer_symbol) = def.loc_expr.value { - 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); + 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) + } + _ => { + let outer_symbol = env.unique_symbol(); + stmt = store_pattern(env, procs, layout_cache, &mono_pattern, outer_symbol, stmt); - // convert the def body, store in outer_symbol - with_hole( - env, - def.loc_expr.value, - def.expr_var, - procs, - layout_cache, - outer_symbol, - env.arena.alloc(stmt), - ) + // convert the def body, store in outer_symbol + with_hole( + env, + def.loc_expr.value, + def.expr_var, + procs, + layout_cache, + outer_symbol, + env.arena.alloc(stmt), + ) + } } } diff --git a/crates/compiler/test_gen/src/gen_str.rs b/crates/compiler/test_gen/src/gen_str.rs index 668cde90dc..d19d8d0b40 100644 --- a/crates/compiler/test_gen/src/gen_str.rs +++ b/crates/compiler/test_gen/src/gen_str.rs @@ -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 + ); +}