Correctly perform record updates that come from thunks

Closes #3908
This commit is contained in:
Ayaz Hafiz 2022-09-06 18:07:22 -05:00
parent 1a9a0d5d01
commit eebe5234f6
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 44 additions and 1 deletions

View file

@ -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,

View file

@ -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
);
}