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

Add the package std module #2104

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cli/src/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn run_tests(
let _ = std::io::stdout().flush();

// Undo the test's lazy wrapper.
let result = prog.eval_closure(Closure {
let result = prog.eval_deep_closure(Closure {
body: mk_app!(val.clone(), Term::Null),
env: Environment::new(),
});
Expand Down
22 changes: 15 additions & 7 deletions cli/tests/snapshot/inputs/doctest/fail_unexpected_error.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
{
foo
| doc m%"
```nickel
foo + "1"
```
```nickel
foo + "1"
```

```nickel
foo + "1"
# => 2
```
```nickel
foo + "1"
# => 2
```
"%
= 1,

bar
| doc m%"
```nickel
{ foo = 1 }
# => { foo = 2 }
```
"%
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
source: cli/tests/snapshot/main.rs
expression: err
---
2 failures
3 failures
error: tests failed
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ expression: out
---
testing foo/0...FAILED
testing foo/1...FAILED
testing bar/0...FAILED
test foo/0 failed
error: dynamic type error
┌─ [INPUTS_PATH]/doctest/fail_unexpected_error.ncl:1:7
Expand All @@ -21,3 +22,15 @@ error: dynamic type error
│ ^^^ this expression has type String, but Number was expected
= (+) expects its 2nd argument to be a Number

test bar/0 failed
error: contract broken by a value
┌─ <unknown> (generated by evaluation):1:1
1 │ std.contract.Equal { foo = 2, }
│ ------------------------------- expected type
┌─ [INPUTS_PATH]/doctest/fail_unexpected_error.ncl:1:9
1 │ { foo = 1 }
│ ^ applied to this expression
8 changes: 8 additions & 0 deletions core/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ impl<EC: EvalCache> Program<EC> {
Ok(self.vm.eval_deep_closure(prepared)?)
}

/// Same as `eval_closure`, but does a full evaluation and does not substitute all variables.
///
/// (Or, same as `eval_deep` but takes a closure.)
pub fn eval_deep_closure(&mut self, closure: Closure) -> Result<RichTerm, EvalError> {
self.vm.reset();
self.vm.eval_deep_closure(closure)
}

/// Prepare for evaluation, then fetch the metadata of `self.field`, or list the fields of the
/// whole program if `self.field` is empty.
pub fn query(&mut self) -> Result<Field, Error> {
Expand Down
Loading
Loading