Repository navigation
v2.18.0 - Wasm `null` in the boxed-Object domain + two analyzer gaps
Compiling a null literal to Wasm threw a bare UnimplementedError: generateASTExpressionNullValue — a leftover TODO — so an ordinary Dart idiom could not be compiled at all:
var a = args.length > 0 ? args[0] : null;null as a boxed value
null is now a real value in the backend's boxed domain: the boxed-Object pointer 0. The heap never allocates at address 0, so it needs no cell, costs no allocation, and is distinguishable from every real box.
- Ternary arms unify. Both arms of a conditional are now coerced to the block's result type, and an arm that is
nullforces that type to a boxedObject— otherwisec ? 1 : nullmixed an i64 with an i32 and produced a module that failed to validate. ??tests a boxed operand. It previously always yielded its left operand ("a Wasm value is never null"), which remains correct in the numeric domain. A boxed operand is now compared against the null box, soa ?? 99falls back whenais null.- String interpolation prints
null, checking the null box before dereferencing a tag. __alloclook-ahead. Boxing allocates, but the alloc export is decided before the Code section while the boxing is only discovered while writing it — so[1, null, 3]anda ?? 99aborted at run time withNo exported Wasm function __alloc. The generator now scans function bodies for anullliteral up front.- An
Object?return decodes tonullinstead of the raw pointer0. Two causes: the return path had noObjectcase, and_typeTag's fallback gave tag5to bothObjectand a class instance, so the runner could not tell a box from a bare instance pointer. A class instance now carries tag8, leaving5unambiguously "boxed value".
Where null genuinely has no representation — a slot whose Wasm type is concrete, such as int (i64) or String (a string pointer) — the compiler now reports an UnsupportedSyntaxError naming the type and suggesting var / Object? / dynamic, rather than emitting a module that fails to validate.
Null-safety analyzer: operands and nullable-to-non-nullable assignment
The analyzer checked unconditional member/method/index access on a nullable, and the null literal assigned to a non-nullable slot. Two adjacent mistakes went unreported:
void run(int? a, int b) {
int? x = a;
int? y = b;
var base = x + (y ?? 0); // x can be null — now reported
}
void run(int? a) {
int x = a; // int? into int — now reported
}unchecked-nullable-operand— a nullable operand in an operation.??,==and!=are exempt (a nullable operand is exactly what they exist to handle), and!or a preceding null check still suppress it.nullable-to-non-nullable— a nullable value assigned to a non-nullable slot: the existing literal-nullerror, one step removed.
Tests
+15 tests, 2450 passing (from 2435), plus Chrome wasm-gc and wasm-chrome. Coverage targets the shapes that were failing: null in a var/Object? slot, ternary arm boxing, Object? return decoding, == null, ?? fallback, both clean-error cases, and the two analyzer rules with their suppression and negative cases.