Skip to content

v2.16.0 - Dart null-safety semantics & null-aware operators

Choose a tag to compare

@gmpassos gmpassos released this 24 Jul 17:41
· 121 commits to master since this release
daeb7ed

Full Dart null-safety support across parse, type-check, runtime, and transpilation, plus a static null-safety analysis pass and Wasm lowering.

Nullable types

  • T? on simple, generic, collection and function types (String?, List<String?>, Map<String, User?>, Future<User?>, void Function()?, String? Function(int)).
  • ASTType.nullable via asNullable() / withoutNullability(); nullability-aware acceptsAssignment (T? accepts T and Null; T rejects Null).

Null-aware operators

??, ??=, ?. (getter + method), ?[, postfix ! (standalone and before access: x!.f, x!.m(), x![i]), and .. / ?.. cascades — parsed, evaluated with correct short-circuit semantics, and Dart round-tripped. ?? is the loosest binary operator in the precedence reducer.

Static analysis (new)

NullSafetyAnalyzer — flow-aware: flags null→non-nullable assignment and unchecked nullable access, with if (x != null) promotion and ?./! suppression. Surfaced through the LSP analyzer.

Cross-language generation

  • Dart: exact round-trip.
  • Kotlin: ?: (Elvis), !!, ?., nullable T?.
  • TypeScript: ??, ?., ?.[, !.
  • C# / JavaScript: native ??. Java / Go / Python / Lua: best-effort.

Wasm

Lowers null-safety within its non-null numeric domain (x!→x, a ?? b→left operand, ?./?[→plain access, T?→numeric type); a null literal remains an explicit unsupported-construct error.

Full test suite green (feature, analyzer, unit, cross-language generation, Wasm codegen, and two declarative .test.xml defs).