mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Merge pull request #3983 from roc-lang/i3908
Correctly perform record updates that come from thunks
This commit is contained in:
commit
bc00b00834
@ -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,
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user