1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-06 16:18:08 +03:00

[Fix] Fix contract.Sequence reversing order (#1510)

* Fix contract.Sequence reversing order

This commit started by fixing tests that didn't fire, because they
involved contracts but were never executed. On of those tests failed
after being fixed, indicating that `std.contract.Sequence` wasn't
preserving the order of applied contracts. This commit fixes this issue
as well by using `fold_left` instead of `fold_right` in the
implementation of `Sequence`.

* Formatting (stdlib)
This commit is contained in:
Yann Hamdaoui 2023-08-08 10:57:19 +02:00 committed by GitHub
parent 5572b444b0
commit 943430e07e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -968,7 +968,11 @@
```
"%
= fun contracts label value =>
std.array.fold_right (fun contract => std.contract.apply contract label) value contracts,
std.array.fold_left
(fun acc contract => std.contract.apply contract label acc)
value
contracts,
label
| doc m%"
The label submodule provides functions that manipulate the label

View File

@ -165,12 +165,17 @@ let {check, Assert, ..} = import "../lib/assert.ncl" in
let f | forall r. { ; r } -> { g : forall r. { ; r } -> { z : Number ; r }; r }
= fun r => %record_insert% "g" r g in
let res = f { z = 3 }
in true,
in std.seq res true,
# std.contract.Sequence
let three = 3 | std.contract.Sequence [ Number, std.contract.from_predicate (fun x => x < 5) ] in
# preserves order
let tag = "some_tag" | std.contract.Sequence [ std.enum.TagOrString, [| 'some_tag |] ]
in true
let SmallerThanFive = std.contract.from_predicate (fun x => x < 5) in
let three | std.contract.Sequence [ Number, SmallerThanFive] = 3 in
three == 3,
# std.contract.Sequence preserves order
let tag | std.contract.Sequence [std.enum.TagOrString, [| 'some_tag |]]
= "some_tag"
in
tag == 'some_tag,
]
|> check