tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.35k stars 89 forks source link

Example from the tutorial fails in Playground #2046

Open vi opened 3 days ago

vi commented 3 days ago

Describe the bug

Cannot export contracts from files (or rather nickel eval files that export contracts), even though it is one of the first features demonstrated in the beginning of the documentation.

To Reproduce

  1. Go to tutorial: https://nickel-lang.org/user-manual/tutorial
  2. Go to "Step 3: Write a contract"
  3. Copy the code snippet (starting with { UserSchema = {)
  4. Go to Playground: https://nickel-lang.org/playground/
  5. Paste the code there, press Run button.

It displays error error: missing definition for 'name'.

Expected behavior

No error, maybe it displays the scheme back to you.

If I do the tutorial steps locally, nickel eval users.ncl succeeds. nickel typecheck users-schema.ncl also succeeds, but it is confusing that nickel eval users-schema.ncl fails - how can import of a module that fails evaluation succeed?

It would be understandable if nickel export fail to export something incomplete, but nickel eval should probably just evaluate the code and print also the incomplete result.

The error here looks just like the error when source code is invalid.


I think Playground should also have typecheck button and should also show version of Nickel.

suimong commented 3 days ago

@yannham (sorry for pinging) may give you a more complete picture, but essentially nickel export = nickel eval + serialization. As for why typecheck succeeds but eval fails, I'd like to make a rather crude analogy to Python: you have a correctly type annotated python script user-schema.py, which takes an required argument name. In this scenario, mypy user-schema.py will succeed (aka "typecheck"), whereas python user-schema.py will fail because you do not provide the name argument.