Repository navigation
v2.17.0 - Null-safety fixes: nullable params, null-aware typing, access chains
Four gaps found by exercising the 2.16.0 null-safety surface end-to-end, plus one pre-existing parser limitation found alongside them.
A T? parameter now accepts a T argument
Calling a method with a String? parameter and a non-null String failed with parameters signature not compatible, though passing null worked. Passing an argument is an assignment, so ASTFunctionParameters.parameterAcceptsType now uses ASTType.acceptsAssignment instead of acceptsType.
ASTTypeString compares nullable in its ==, so String? != String and acceptsType rejected the argument; int?/double? only appeared to work because StrictType ignores nullable. A non-nullable parameter still rejects null.
A null-aware access now reports a nullable static type
Storing a short-circuited result in a local failed — var v = s?.length on a null receiver threw Class not set for type: Null, and var v = xs?[0] threw Can't cast initial (null) value to type: int. ?. (getter and method) and ?[ now resolve to T?, and resolving the type of an access whose receiver is null reports Null instead of looking for a class. Using the result in a return, inline with ??, or in a string interpolation already worked and is unchanged.
Member-access chains parse
a.b.c, a.b?.c, a.b!.c, a.b.m(), a.b?.m(x) and chained writes (a.b.c = v) previously failed: the grammar accepted only a single identifier receiver, so a.next?.value reported SyntaxError: digit expected (the ? read as the start of a number) and even plain a.next.value reported "(" expected.
A new chain rule folds each segment onto the previous one, wrapping it in the new ASTExpressionVariable (an ASTVariable backed by an expression), so the existing object-access nodes supply the runtime, null-aware and code-generation behaviour. Chains work at any depth, in any mix of ., ?. and !.
The rule requires two or more segments, so single-segment access keeps its own rules and enum entries, static fields and import prefixes resolve exactly as before.
A field read off a parenthesized receiver ((a).v, (a)?.v) also parses now — previously only (expr).method() did. (expr).m().field remains unsupported.
?? and ??= no longer leak into targets that cannot compile them
Java, Lua, Python and Go emitted a ?? b verbatim, and ??= leaked into every target — including Kotlin, which had a correct ?: for ?? but no hook for the assignment form.
?? now goes through an overridable renderNullCoalesce, and ??= is lowered to t = t ?? v wherever supportsNullCoalesceAssignment is false, so each target defines only one desugaring:
| Target | a ?? b |
|---|---|
| Java | (a != null ? a : b) |
| Python | (a if a is not None else b) — is not None, so 0/''/False survive |
| Lua | IIFE with an explicit nil test |
| Kotlin | ?: (and t = t ?: v for ??=) |
| Dart, C#, JS, TS | unchanged — both operators are native |
| Go | UnsupportedSyntaxError |
Lua needs the IIFE because both a or b and the a ~= nil and a or b idiom return b for a non-nil false. It also binds a to a local, so it is evaluated once rather than twice like the ternary targets.
Go is deliberately unsupported: it has neither a null-coalescing operator nor a conditional expression, and this generator maps a nullable T? onto a plain Go T, which for a value type cannot be compared to nil — any rendering would be code that does not compile. Representing T? as *T throughout the Go generator is separate work.
Also adds an overridable resolveASTAssignmentOperatorText, which lets the Python generator drop its whole generateASTExpressionVariableAssignment override.
Tests
The null-safety suite previously exercised ?. only in return position on user classes — precisely the shape that already worked, which is why these slipped through. New coverage targets the failing shapes directly, and the generation suite gains per-target desugaring assertions plus a guard that no target leaks a literal ??/??=.
2435 VM tests pass (up from 2410), plus WasmGC and wasm-chrome in Chrome.