Known gaps
Katnip builds real, runnable Scratch projects today, and the list of things it cannot do yet is short and shrinking. The analyzer runs a little ahead of the code generator, so a few features type-check before they build; a couple go the other way, where the analyzer holds something back until the lowering exists.
Every entry here comes with something that works instead. Skim it before a big project and you will not be surprised later.
How a gap shows up
Section titled “How a gap shows up”| Mode | What you see | Examples |
|---|---|---|
| 🔴 Build error | check passes, build fails loudly |
console.log, typeof, top-level statements |
| 🔴 Check error | check refuses it, with a message |
a computed value in an enum slot |
A construct the compiler cannot lower stops the build with a message, rather than producing a project that runs and gives a wrong answer.
Recently closed
Section titled “Recently closed”List returns and whole-list copies
Section titled “List returns and whole-list copies”A procedure can return a list<T>, and a = b; or private c: list<num> = b; copies a list. See Returning a list and Copying a whole list.
proc pair(n: num) -> list<num> { return [n, n * 10]; }a = pair(1);b = a;Sprites in other files
Section titled “Sprites in other files”import "./cat.knip" as *; or import Cat from "./pets.knip"; adds the file’s sprites to the build, so a project can be one file per sprite. See Unprefixed imports.
Cloud variables and Scratch names
Section titled “Cloud variables and Scratch names”public cloud score: num = 0; declares a cloud variable, and as "..." keeps a Scratch name that isn’t an identifier, on variables, sprites, costumes and sounds. See Variables.
List fields in structs
Section titled “List fields in structs”struct Buffer { len: num, data: list<str> } works. See List fields.
Methods on your own types
Section titled “Methods on your own types”A user procedure whose first parameter is self is a method on any type, including num, str and your own structs. See Methods.
list.remove, merge and the dict methods
Section titled “list.remove, merge and the dict methods”list.remove, list.insert, list.merge, console.input and all five dict methods build. See list and dict.
private gone: num = scores.remove(1);scores.merge(other);if (stock.contains("apple")) { stock.merge(more); }private name: str = console.input("Name?");List and dict parameters
Section titled “List and dict parameters”A procedure can take a list or dict, and writes reach the caller’s list. See Passing a list to a procedure.
Module state
Section titled “Module state”A module owns its variables, lists, dicts and structs, and an importer can read and write the public ones. See Modules and imports.
sound, motion.x and motion.y
Section titled “sound, motion.x and motion.y”There is a sound namespace, and motion.x(), motion.y() and motion.getPosition() read the sprite’s position.
Decimal literals
Section titled “Decimal literals”A whole number written with a point keeps it, so math.random(0.0, 1.0) stays fractional.
**, slices and tuple patterns
Section titled “**, slices and tuple patterns”private area: num = side ** 2; # also **= and math.powlooks.say(name[1:3]); # 1-based, stop-inclusive; lists too(lo, hi) = bounds(); # also (a, b) = (b, a);See Operators, Lists and dicts and Procedures.
Calling twice in one statement
Section titled “Calling twice in one statement”f(1) + f(2) used to read the second result twice. Each call now keeps its own value. The one remaining limit: a value held across a recursive call in the same statement can be overwritten, so split that statement in two.
forever and repeat
Section titled “forever and repeat”Both have source syntax now. See Control flow.
forever { motion.turn(1); }repeat (4) { motion.forward(10); }Data files
Section titled “Data files”import("./levels.csv") and import("./scores.json") load a flat file into a list or dict at compile time. See Loading a list or dict from a file.
Decompiling
Section titled “Decompiling”katnip decompile game.sb3 writes a .kpkg with the source, costumes and sounds, and --split gives one file per sprite. See the CLI page for the limits.
math.random, math.round and math.mod
Section titled “math.random, math.round and math.mod”These no longer need a hand-written @opcode binding.
Comments inside multi-line statements
Section titled “Comments inside multi-line statements”A comment between tokens, such as after an element of a multi-line list, no longer causes a parse error.
Costumes, sounds and the stage
Section titled “Costumes, sounds and the stage”Sprites declare their own assets, and the stage has a block of its own:
stage { costume "./assets/sky.svg"; events.onFlag() { looks.switchBackdrop("sky"); }}
sprite Cat { costume "./assets/cat.svg" as idle; sound "./assets/meow.wav"; events.onFlag() { looks.switchCostume("idle"); }}Paths are relative to the file; a missing file fails the build. sprite stage { } is now a parse error — use stage { }. See Sprites and events.
Imports build now
Section titled “Imports build now”An imported procedure lowers into every target that calls it, including procedures it calls in turn, and imported literal constants fold at the call site:
public SIDES: num = 3;public proc twice(n: num) -> num { return n * 2; }public proc quad(n: num) -> num { return twice(twice(n)); }import "./lib.knip";
sprite Cat { events.onFlag() { looks.say(f"{lib.quad(2)} {lib.SIDES}"); # builds }}Aliases (import "./lib.knip" as geo;) build too.
Casts build now
Section titled “Casts build now”Num(), Str() and Bool() are @lower = "builds" procedures. They inline the value unchanged and cost nothing:
private answer: str = sensing.answer();private n: num = Num(answer); # buildsThey are type-checker assertions, not runtime conversions — Scratch coerces at runtime anyway, so Num("abc") does not become 0, it stays "abc" in the block tree. Use them to satisfy the checker where you know better than it does.
List() and Var() let a variable fill a list slot and the other way round. Bool(x) in a boolean slot puts x in as-is. typeof() still has no codegen. See Casts.
Lists and dicts declared inside a script or procedure
Section titled “Lists and dicts declared inside a script or procedure”They lower — the list is cleared and refilled at the declaration site, on every run, rather than baked into the project file once like a top-level list:
events.onFlag() { private xs: list<num> = [1, 2, 3]; # builds looks.say(f"{xs[1]}");}The math functions
Section titled “The math functions”math.abs, floor, ceil, sqrt, sin, cos, tan, asin, acos, atan, ln, log, epow and the underlying math.op all build. math.pow is back, and is what ** calls.
Limits to plan around
Section titled “Limits to plan around”zip() as a value
Section titled “zip() as a value”🔴 Used as a value, range(), zip() and enumerate() all stop the build. Use them in a for header instead.
Passing, returning and copying lists and dicts
Section titled “Passing, returning and copying lists and dicts”🔴 A literal can’t be passed to a list or dict parameter, or to merge. Declare it first. A generated copy of a procedure with list parameters also drops @proccode.
🔴 A procedure can’t return a dict or a list of structs, and a recursive one can’t return a list. A whole dict can’t be replaced, and a + b on two lists stops the build; use merge.
Dict keys ignore case
Section titled “Dict keys ignore case”🟡 stock["APPLE"] and stock["apple"] are the same entry, because Scratch’s list lookups are case-insensitive. keys() and values() are read-only, so store one in a list to change a copy.
Module limits
Section titled “Module limits”🔴 Two structs with one name but different fields are an error across files. Rename one. A file that declares sprites has to be imported with as * or a name list.
Struct limits
Section titled “Struct limits”🔴 Structs compile to one Scratch variable (or list) per field, so a struct only works through its fields.
These fail the build:
- a whole struct inside an interpolated string:
f"{p}" contains,indexOfandmergeon alist<Struct>zip()over alist<Struct>
These are check errors:
- passing a whole struct where a scalar is expected:
looks.say(p) - comparing structs:
p == q - constructing a struct declared in an imported module:
geo.Point(x = 1, y = 2)
A struct with a list field also can’t be stored in a list, or copied, passed or returned as a whole.
Instead: work field by field.
if (p.x == q.x && p.y == q.y) { ... }looks.say(f"{p.x}, {p.y}");Statements outside a handler
Section titled “Statements outside a handler”🔴 Executable code at the top level or directly in a sprite stops the build:
looks.say("hi"); # this statement isn't allowed at the top levelA file with no sprite at all gets a warning: no sprites declared, so this builds to an empty project. Warnings print but do not stop the build.
Stops at build time
Section titled “Stops at build time”These fail loudly with a message, so there is nothing to hunt for.
The katnip_* builtins have no codegen
Section titled “The katnip_* builtins have no codegen”🔴 These resolve to placeholder opcodes with no slot metadata. Using one throws no slot metadata at build time.
| Blocked | Instead |
|---|---|
console.log / warn / error |
looks.say(...), or a log list |
typeof() |
— |
zip(), enumerate() as a value |
use them in a for header, where both fold into the loop counter |
Num(), Str() and Bool() used to be on this list. They are not any more — see Casts build now.
The namespace call form for methods fails at codegen
Section titled “The namespace call form for methods fails at codegen”🔴 Methods — procedures whose first parameter is self — have two call forms. Both type-check; only the receiver form builds.
scores.contains(4); # ✅list.contains(scores, 4); # 🔴 "undeclared list 'list'"str.contains(name, "at"); # 🔴 "undeclared variable 'str'"Codegen treats the namespace as a variable name. Use the method form.
Held back by the analyzer, on purpose
Section titled “Held back by the analyzer, on purpose”No cast to an enum
Section titled “No cast to an enum”🔴 A literal whose value is one of an enum’s member values is accepted in an enum slot, and so is a member reference. A computed value of the backing type is not, and there is no Enum(x) escape hatch to force one:
pen.setAttr(pen.ColorParam.COLOR, 10); # ✅ memberpen.setAttr("color", 10); # ✅ literal, coercedprivate attr: str = "color";pen.setAttr(attr, 10); # 🔴 "expects one of its members here, not a computed 'str'"This is deliberate: the slot is a Scratch menu, a shadow block, so dropping a reporter into it is legal but almost never what you meant. The diagnostic points at the member form.
Instead: branch on the value and pass a literal in each arm.
if (mode == 1) { pen.setAttr("color", 10); }else { pen.setAttr("saturation", 10); }The six open menus — motion.Target, sensing.TouchTarget, sensing.DistanceTarget, sensing.ObjectTarget, clone.CloneTarget, looks.Backdrop — also list sprite, costume, and backdrop names, so their parameters keep an | str arm and take any string, computed or not.
Dicts cannot be returned
Section titled “Dicts cannot be returned”🔴 -> dict<K, V> and -> list<Struct> are rejected at check time. A plain list<T> return works.
Instead: mutate a global dict.
Not started yet
Section titled “Not started yet”Comments stay in the source
Section titled “Comments stay in the source”🔴 All six comment forms lex correctly, and NodeBase.comment exists on the AST. The parser drops comment tokens for now, so nothing is written to the sb3 comment map yet. The expanded / collapsed distinction is there for when it is.
The ignored forms (#! and #[ ]#) do work, in that they are dropped at the lexer.
Monitor layout
Section titled “Monitor layout”🔴 Monitors can be shown and hidden but not positioned or styled.
On the roadmap
Section titled “On the roadmap”| Feature | Note |
|---|---|
break / continue |
Not yet — break is reported as an undefined name |
switch fallthrough |
Not planned |
switch exhaustiveness over enums |
Not checked — always write a default |
| User-defined generics | Typevars are a stdlib facility |
math.min / math.max |
Write them with an if |
Optional -> void |
A procedure must declare its return type, even void |
| Language server, formatter, source maps | Later; the VS Code extension already has hover and member completion |
check on costume and sound files |
The CLI’s check does not read them; build and the editor do |
lower on projects with assets or data |
The CLI’s lower reports them as missing |
Which examples to learn from
Section titled “Which examples to learn from”examples/all.knip (every feature that lowers, once each), examples/assets.knip and examples/codegen.knip are kept building, and are the best reference for “does this actually build”:
katnip build examples/all.knipexample.knip, typeof.knip, oos.knip, overload.knip, proc.knip, showcase.knip and stdlib.knip are older analyzer tests from before codegen existed. They use console.log, typeof, math.pow and events.onflag, so treat them as history rather than a template.