Comments (2)
That's a bad error message indeed. Thanks for reporting. For the record, here is what happens: {a : "str"}
is interpreted as a type expression as per the syntax rules of the unified types/terms syntax (a record with only field without definition and :
annotations). Indeed, {a: Number}
is a record type.
When used at run-time, a type evaluates to its contract. Its contract is a function of the form fun label value => ...
(at least once evaluated), and is built from the internals built-in contracts. In practice, this is elaborated to $record ..some_params..
where $record
is a builtin internal function. This has type Label -> Dyn -> Dyn
, and indeed is a contract waiting to be applied, which isn't serializable.
That types are automatically translated to their contract function is dubious and has actually been discussed in #1775. A better behavior would probably to keep it as a Type
node in the AST, which would greatly improve error messages like this one (we could keep transforming them when they're used as a contract somewhere).
Separately, we should probably emit a warning when a value is used as a type/contract but has no chance to ever make sense (currently constants indeed don't have any reasonable meaning, although this could change, where {foo | "bar"}
could mean {foo | MustEquals "bar"}
, although I'm not sure this is a great idea - just mentioning that this could change one day).
from nickel.
Separately, we should probably emit a warning when a value is used as a type/contract but has no chance to ever make sense (currently constants indeed don't have any reasonable meaning, although this could change, where
{foo | "bar"}
could mean{foo | MustEquals "bar"}
, although I'm not sure this is a great idea - just mentioning that this could change one day).
I think if {foo : "bar"}
has no valid use case today, it makes sense to just throw an error. It can always be re-enabled in the future without breaking compatibility. No decision about future use of {foo : "bar"}
has to be made right now.
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.