Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze records on insert/remove/update. #2131

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/stdlib/std.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -3187,7 +3187,7 @@
# => error
```
"%%
= fun field content r => %record/insert% field r content,
= fun field content r => %record/insert% field (%record/freeze% r) content,

insert_with_opts
: forall a. String -> a -> { _ : a } -> { _ : a }
Expand Down Expand Up @@ -3221,7 +3221,7 @@
# => error
```
"%%
= fun field content r => %record/insert_with_opts% field r content,
= fun field content r => %record/insert_with_opts% field (%record/freeze% r) content,

remove
: forall a. String -> { _ : a } -> { _ : a }
Expand Down Expand Up @@ -3256,7 +3256,7 @@
# => error
```
"%
= fun field r => %record/remove% field r,
= fun field r => %record/remove% field (%record/freeze% r),

remove_with_opts
: forall a. String -> { _ : a } -> { _ : a }
Expand Down Expand Up @@ -3284,7 +3284,7 @@
# => error
```
"%
= fun field r => %record/remove_with_opts% field r,
= fun field r => %record/remove_with_opts% field (%record/freeze% r),

update
: forall a. String -> a -> { _ : a } -> { _ : a }
Expand Down Expand Up @@ -3327,6 +3327,7 @@
```
"%
= fun field content r =>
let r = %record/freeze% r in
let r =
if %record/has_field% field r then
%record/remove% field r
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# test.type = 'error'
#
# [test.metadata]
# error = 'EvalError::MissingFieldDef'
#
# [test.metadata.expectation]
# field = 'bar'
((std.record.insert "bar" 1 { foo = bar + 1, bar | optional }) & { bar | force = 2 }).foo
15 changes: 15 additions & 0 deletions core/tests/integration/inputs/records/freezing_ops.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# test.type = 'pass'
[
((std.record.insert "baz" 1 { foo = bar + 1, bar = 0 }) & { bar | force = 2 }) == { foo = 1, bar = 2, baz = 1 },
((std.record.insert_with_opts "baz" 1 { foo = bar + 1, bar = 0 }) & { bar | force = 2 }) == { foo = 1, bar = 2, baz = 1 },
(
(std.record.remove "to_remove" { foo = bar + 1, bar = 0, to_remove = false, rev_dep = to_remove })
& { bar | force = 1, to_remove = true }
) == { foo = 1, bar = 1, to_remove = true, rev_dep = false },
(
(std.record.remove_with_opts "to_remove" { foo = bar + 1, bar = 0, to_remove = false, rev_dep = to_remove })
& { bar | force = 1, to_remove = true }
) == { foo = 1, bar = 1, to_remove = true, rev_dep = false },
((std.record.update "bar" 1 { foo = bar + 1, bar = 0 }) & { bar | force = 2 }) == { foo = 1, bar = 2, },
]
|> std.test.assert_all
Loading