Comments (2)
There are different ways to go about this, but note that in general checking a local contract might require values from the outer scope, or even values that aren't known at writing time (such as inputs of the configuration).
One way could be to try to evaluate the expression, and just ignore any error that isn't a contract error (such as missing field, or even just classify errors that should be reported immediately versus the ones that could stem from evaluating just a fragment of the program).
Another possibility, for simple cases, could be to try to infer a type for the subexpression, and compare that to basic contracts - if it fails to typecheck, we can't say anything, but if it succeeds with a type that is incompatible with the contract, then there is a problem. Both approaches (and there's probably more, such as just running the full program and reporting any error on command) have different trade-offs:
- Tthe partial evaluation one is simple and generic, and handle custom contracts, but can't handle unknown inputs (i.e won't report obviously wrong things such as
{ foo | Number, bar | String = foo ++ "a"}
) - The typing approach can't handle custom contract, and can't handle ill-typed terms (that aren't necessarily wrong, just not accepted by the static typechecker), but better handles incomplete values.
Or maybe we can combine both?
from nickel.
I believe this is closed by the same PR as #1586, giving stuff like this in practice:
Feel free to re-open, or open new issues for more specific aspects of in-code contract evaluation.
from nickel.
Related Issues (20)
- Confusing merge behaviour in `std.record.{update,remove}` HOT 1
- `std.string.find_all` HOT 1
- Add `record.has_field_all` and `record.fields_all` HOT 1
- Add raw strings
- NLS crashes on recursive definitions HOT 11
- Proposal: freeze recursive records upon insert/remove/update/map
- NLS reports same diagnostic message multiple times HOT 3
- VSCode extension does not show hints for functions annotated with record contract HOT 1
- VSCode Extension should not disregard cursor position and collapse all symbol breadcrumbs to "..." in all occasions
- Weird `nix develop` error HOT 4
- Strange error in std.array.any HOT 2
- Provide contract interface to pyckel HOT 1
- Add functions to create and generically unwrap enum variants HOT 1
- Inconsistent behaviour while loading multiple files vs single file HOT 2
- Getting `record_insert: tried to extend but already exists` when using patterns with duplicate bound variables HOT 2
- Memory leak with long-running nickel process HOT 1
- Opaque foreign values
- Update documentation for new pattern features
- Accessing late-bind field fails HOT 6
- Context-sensitive completion in match cases
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nickel.