Giter VIP home page Giter VIP logo

Comments (2)

yannham avatar yannham commented on May 27, 2024 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.

szlend avatar szlend commented on May 27, 2024 1

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.