Merge pull request #3983 from roc-lang/i3908

Correctly perform record updates that come from thunks
This commit is contained in:
Folkert de Vries 2022-09-07 12:19:29 +02:00 committed by GitHub
commit bc00b00834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
);
}