Skip to content

v0.46.0

Choose a tag to compare

@github-actions github-actions released this 01 Dec 18:04
· 32 commits to master since this release
fecf4e3

Highlights

Arguments are checked strictly, in one place. One core rule decides whether an argument fits its parameter. The editor, kscript check and the run all use it and report the same words:

rolls = [4, 6, 6, 2]
$rolls->common(1, least)          // [2]: least on its own is true
$rolls->common(1, least: {})      // Error: The 'least' argument needs true or false, but this is a map.
$rolls->common(fn() => 2)         // Error: The 'count' argument needs a number, but this is a function.
$rolls->common(1, by: 3)          // Error: The 'by' argument needs a function, but this is a number.

A flag given a value offers the quick fix "Write least on its own".

Block functions must give a value where it is used. An empty or return-less block passed to ->map(), ->common(by:) and similar is an error. ->each() and blocks that throw are fine.

Trailing commas. A comma before the closing bracket on the same line is an error in every list: fn(a,), [1, 2,], { a: 1, }, ->take(2,) and fn name(a,). The quick fix is "Remove the comma". Lists written one item per line can still end with a comma.

A default main script. kscript and kscript run with no file now run the project's main script. They look for app.main in kscript.json, then main.kscript or index.kscript. kscript run tools runs a folder's main script. VS Code gets a Run Project command.

Declaration blocks. Completion inside type, native type, model, job, error, extend and enum blocks offers only what that block holds, at every caret position. A statement written there (echo, if, return) is now an error that says where to put it. Keyword hovers link to the docs.

Testing. @check_script(path) returns what kscript check reports for another script, so tests can check editor errors next to run errors.

Behaviour changes

  • A number passed for a true/false parameter is an error. It used to be read as true when it wasn't 0.
  • ->map(fn(x) { ... }) with no return is an error. Use ->each() when only what the block does matters.
  • [1, 2,], fn(a,) and other one-line lists that end in a comma are errors.
  • A statement inside a type, model, job or error block is a KS3007 error.

What's Changed

  • Suggest only what a declaration's block holds, and link keyword hovers to the docs by @kylepantall in #339
  • main.kscript and index.kscript are default entry scripts by @kylepantall in #337
  • Strictly check argument kinds, block results and trailing commas by @kylepantall in #338

Full Changelog: v0.45.0...v0.46.0