Repository navigation
v2.35.0
The Wasm backend now compiles every Dart example of the web playground:
nullable values, top-level variables, setters, extensions, records and set
literals, plus fixes to async methods.
Nullable values
int?,double?,num?andbool?are stored boxed. They use the
same representation as anObject: a pointer, where 0 isnull.
String?,List?,Map?and class types are already pointers, and 0 is
theirnull. This applies to locals, parameters, fields, returns and
globals.- Silently wrong results fixed:
- a
String?holdingnullcame back as"", so??never fell back; s?.lengthandl?[0]onnullgave0instead ofnull.
- a
nullcrosses the host boundary. Anullargument for a nullable
parameter used to fail withCannot convert null to a BigInt. Anull
return now reaches the caller asnull.??=compiles, and is assigned only when the target isnull. Before,
it failed withWasm Operator not supported: nullCoalesce.??unboxesint? ?? intto a plainint, and tests a nullable
pointer against 0.== nullworks on a nullable pointer. Before, it was constantfalse.!unboxes the value. Onnullit raises
ApolloVMNullPointerException: Null check operator used on a null value,
which acatchinside the function catches; elsewhere it traps. It used to
passnullthrough.?.,?[,!.and member-access chains work on any receiver
expression:a.next.name,a.next?.next?.name,a.next!.name,
head.next.value = 20, and on top-level variables and fields. Nullable
class-typed fields (Node? next) compile.- Printing a
nullString?or instance givesnull.
Top-level variables
Top-level variables compile to module globals. Before, compilation crashed
with Can't find local variable. A literal number seeds its global. Any
other initializer (final List<String> log = [];) runs in an exported
__init_globals, which the runner calls once per module instance before the
entry function. An exported function also calls it on entry (it runs only
once), so another host sees the globals initialized. Functions lowered for
try/catch or async don't make that call yet, and rely on the runner.
Locals and fields shadow them, and g++, compound assignment,
interpolation and method calls (log.add(…)) work on them, and on static
fields too.
Setters
A setter compiles to a method named x=. obj.x = v, compound assignment
(which reads through the getter) and a bare x = v inside the class call it.
A bare getter name inside the class reads through the getter. Static setters
are still refused.
Extensions
Extension methods and getters on a core type (int, String, …) or a user
class compile to functions that take the receiver first. A call picks the
extension by the receiver's static type; a member the class declares itself
wins. Inside an extension, this.toUpperCase() and other implicit-this
calls work. Extension setters and static extension members are refused.
Records and set literals
- A record compiles to a heap struct: positional fields first, then named
ones sorted by name. Supported: literals,r.$1/r.name, structural
==(nested records too), printing in Dart's format ((1,),
(a: 1, b: 2)), and records as list and set elements. A record converts
to a declared layout:return (1, 2);from a(double, int)or an
(int?, int)function. - A set literal compiles to the list layout, skipping elements equal to
one already in (boxed values compare by value), and keeping insertion
order. Supported:length,
isEmpty/isNotEmpty, printing ({1, 2}).
Fixes
asyncmethods:var x = await doubleIt(n)on a siblingstatic
method typedxasFuture<int>. With a typed local, Chrome rejected the
module. The class-method wrappers dropped theasyncmodifier, so their
Wasm return type wasFuture<T>. Inside anasyncmethod, an awaited
siblingstaticis now resolved as a module function, not a host import.- A call used as a statement inside a loop (
next('x');) left its result
on the stack, and the module failed to validate. ?:takes its type from its arms when the static type isdynamic,
e.g. inside a setter. Before, it could produce ani32block forint
arms.- A
doublefield initialized with an int literal (double c = 0;) is
converted. Before, the module failed to validate. Field assignments convert
too. - A list literal whose element type is unknown statically (
[a, 5],
whereais a parameter) takes its type from the elements. Before, it
stored boxes that aList<int>parameter misread. - Printing a boxed number (
print(x)withObject x = 5) exports the
__allocits host conversion needs. Before, it failed at run time. - Interpreter: a field shadows a top-level variable for writes too.
Inside a method,count = 7andcount++wrote the top-levelcount,
while reads used the fieldcount.