Skip to content

v2.19.0 - `x == null` no longer throws; Wasm null equality; group chains; Go nil

Choose a tag to compare

@gmpassos gmpassos released this 25 Jul 00:09
· 115 commits to master since this release
9930898

Four gaps fixed. The first is the serious one.

x == null no longer throws

The most common null check in Dart threw for any typed left operand:

int? a = 1;      if (a == null) { … }   // _TypeError: 'Null' is not a subtype of 'FutureOr<int>'
String s = 'x';  if (s == null) { … }   // 'Null' is not a subtype of 'FutureOr<String>'

No ternary, nullable slot or ?. needed. Only the reversed null == x worked.

ASTValue.equals read the other operand through _getValue, which casts it to this value's T — right for arithmetic, where a mismatched operand is a real error, but wrong for equality, where a different type must compare false. Equality now reads both operands uncast, so x == null is false and 1 == 'x' is false, and neither throws. The three equals overrides (ASTValueStatic, ASTValuePrimitive, ASTValueNum) carried the same cast and were fixed with it.

This predates the null-safety work — it is in the base ASTValue — but 2.16.0 made x == null the idiom people reach for, so it went from obscure to prominent.

Wasm: == null / != null against the null box

With null representable since 2.18.0, the equality paths had to learn about it. A comparison against a null literal is now recognised before the String and numeric paths:

  • a boxed operand compares its pointer against the null box, so a[0] == null on a List<Object> answers correctly. It previously took the __streq route and compared contents against address 0, reporting a non-null String as null.
  • a concrete operand (int, double, String, an instance) can never be the null box, so the result is constant — and a valid module. String s; s == null previously pushed two i32 handles into an i64.eq and produced a module that failed to validate.

Grammar: (expr).m().field

A group invocation followed by member access did not parse — the group-invocation rule chains only further invocations, so a trailing .field had nothing to match it. A new rule reuses that rule for the head and folds the trailing segments. It requires at least one trailing segment, so (expr).m() keeps its own rule and parenthesized arithmetic is untouched.

Go: no more var s string = nil

The Go generator emitted var s string = nil for a nullable local — source that does not compile. It now reports an UnsupportedSyntaxError naming the type, consistent with how ?? is already handled. A List/Map still accepts nil, since those become a Go slice/map, which are nilable.

Go's nullable representation remains open: supporting T? properly means generating *T throughout — declarations, zero values, every dereference, and parameter/return types.

Tests

+10 tests, 2460 passing (from 2450), plus Chrome wasm-gc and wasm-chrome. The equality bug survived because the suite compiled == null in flow-promotion cases but never ran one against a typed operand; the new tests do.