Skip to content

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.

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.


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;

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.

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.

struct Buffer { len: num, data: list<str> } works. See List fields.

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, 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?");

A procedure can take a list or dict, and writes reach the caller’s list. See Passing a list to a procedure.

A module owns its variables, lists, dicts and structs, and an importer can read and write the public ones. See Modules and imports.

There is a sound namespace, and motion.x(), motion.y() and motion.getPosition() read the sprite’s position.

A whole number written with a point keeps it, so math.random(0.0, 1.0) stays fractional.

private area: num = side ** 2; # also **= and math.pow
looks.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.

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.

Both have source syntax now. See Control flow.

forever { motion.turn(1); }
repeat (4) { motion.forward(10); }

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.

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.

These no longer need a hand-written @opcode binding.

A comment between tokens, such as after an element of a multi-line list, no longer causes a parse error.

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.

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:

lib.knip
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.

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); # builds

They 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]}");
}

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.


🔴 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.


🟡 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.


🔴 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.


🔴 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, indexOf and merge on a list<Struct>
  • zip() over a list<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}");

🔴 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 level

A 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.


These fail loudly with a message, so there is nothing to hunt for.

🔴 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.


🔴 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); # ✅ member
pen.setAttr("color", 10); # ✅ literal, coerced
private 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.


🔴 -> dict<K, V> and -> list<Struct> are rejected at check time. A plain list<T> return works.

Instead: mutate a global dict.


🔴 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.


🔴 Monitors can be shown and hidden but not positioned or styled.


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

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”:

Terminal window
katnip build examples/all.knip

example.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.