diff --git a/crates/compiler/mono/src/ir.rs b/crates/compiler/mono/src/ir.rs index abe24826fb..8cdcc6700d 100644 --- a/crates/compiler/mono/src/ir.rs +++ b/crates/compiler/mono/src/ir.rs @@ -4874,7 +4874,10 @@ pub fn with_hole<'a>( stmt = Stmt::Let(*symbol, access_expr, *field_layout, arena.alloc(stmt)); - if record_needs_specialization { + // If the records needs specialization or it's a thunk, we need to + // create the specialized definition or force the thunk, respectively. + // Both cases are handled below. + if record_needs_specialization || procs.is_module_thunk(structure) { stmt = specialize_symbol( env, procs, diff --git a/crates/compiler/test_gen/src/gen_records.rs b/crates/compiler/test_gen/src/gen_records.rs index adb7d0dae5..d339ba24a7 100644 --- a/crates/compiler/test_gen/src/gen_records.rs +++ b/crates/compiler/test_gen/src/gen_records.rs @@ -1044,3 +1044,43 @@ fn generalized_accessor() { RocStr ); } + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn update_record_that_is_a_thunk() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [main] to "./platform" + + main = Num.toStr fromOriginal.birds + + original = { birds: 5, iguanas: 7, zebras: 2, goats: 1 } + + fromOriginal = { original & birds: 4, iguanas: 3 } + "# + ), + RocStr::from("4"), + RocStr + ); +} + +#[test] +#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))] +fn update_record_that_is_a_thunk_single_field() { + assert_evals_to!( + indoc!( + r#" + app "test" provides [main] to "./platform" + + main = Num.toStr fromOriginal.birds + + original = { birds: 5 } + + fromOriginal = { original & birds: 4 } + "# + ), + RocStr::from("4"), + RocStr + ); +}