Repository navigation
v2.36.0
New Dart syntax, run by the interpreter and compiled to Wasm: labeled loops,
collection if / for / spread, user operators, generic functions, static
and top-level getters, mixins and member chains on calls and literals. The
Wasm backend gains catches of what a called function throws, recursive local
functions, lists of instances, static access from outside a class and number
methods. Several interpreter bugs are fixed too.
Dart syntax
- Labeled loops.
outer: for (…)withbreak outer;/continue outer;,
from nested loops and from inside aswitch. Generated for Dart, Java, Go,
JS/TS (outer: for) and Kotlin (outer@ for,continue@outer). C#, Lua and
Python refuse them withUnsupportedSyntaxError, and Go and Kotlin refuse a
labeled block (b: { … break b; }), which they can't express. - Collection elements in list and set literals:
if (c) a else b,
for (var i = 0; i < n; i++) i,for (var e in l) e,...land...?l,
nested in each other. Regenerated as Dart and kept by the binary format
(new tags 131–137). Other targets and Wasm refuse them. - User operators.
V operator +(V o), and the same for
- * / ~/ % < > <= >= == & | ^ << >>. They dispatch on the left operand's
class, and!=negates a user==. Dart output keeps them; JS/TS/Kotlin and
the other targets refuse them instead of emitting invalid code. - Generic functions and methods:
T first<T>(List<T> l), called as
first<int>(l)orfirst(l). Erased at run time, like generic classes. staticand top-level getters:static int get three => 3;(read as
C.three) andint get two => 2;. Dart output keepsstatic; Kotlin
refuses astaticgetter.- Mixins.
mixin M { … }andclass A with M1, M2(after anextends,
too). The mixin's fields, methods and accessors are copied into each class
that doesn't declare them; a later mixin wins over an earlier one. - Member chains on calls and literals:
P(3).twice().x,P.zero().x,
g()?.x,[1, 2].length,{1, 2}.length,'abc'.length. - Parser fix. A declaration such as
List<String> logis first tried as a
generic function namedList. That attempt erasedStringas a type, so a
laterString f()parsed with adynamicreturn.
Wasm
- A
catchof what a called function throws. An untypedcatch (e)
whosetrycalls a throwing function binds the value boxed from its
runtime tag. It used to bind the raw value as anint, printing a String's
pointer (e.g.24).return 'ok ${g(a)}'inside atrycompiles. The value is computed
first, and the handler runs if the call threw.var r = g(a);inside atryno longer produces an invalid module.
- A recursive local function passes its environment to itself. The module
failed to validate. - Lists of class instances (
[P(1), P(2)],List<Shape>,m.add(P(2))).
Avarlist or loop variable takes the element type, and printing uses a
usertoString(). staticmembers from outside the class:C.n,C.n = v,C.n += v,
C.m(args)andstaticgetters. Astaticfield initializer that isn't a
literal number runs in__init_globals; before, the field started at 0.- Number methods:
toString,toDouble,toInt,round,floor,
ceil,truncate,abs,clamp,isEven,isOdd,isNegative,
int.parse. Call chains (a.abs().toString(),(a - b).abs()) used to be
ignored after the first call. - New syntax compiled: labeled
break/continue, user operators, mixins,
top-level getters and member chains. A user operator that returnsbool
works as a condition. - Invalid modules fixed:
- two
for (var i …)loops in one function declared an extra local, which
shifted the types of the scratch locals; - a
vartypeddynamicin one loop and as a class in another clashed.
- two
- Wrong results fixed:
- nested
for-eachloops shared their iteration locals, so after the inner
loop the outer one resumed over the inner list; n.clamp(0, m.clamp(1, 5))clampedminstead ofn;- a closure calling a different capturing local function passed its own
environment.
- nested
- A chain of user operators (
a + b + c + …) compiles each operand once; it
used to compile them again at every level.a == nulldoesn't call a user
operator ==.
Interpreter
- Core methods.
- List:
join,sort(with a comparator),map,where,any,every,
fold,reduce,forEach,toList,reversed. - Map:
forEach,putIfAbsent,entries(each entry readse.key/
e.value). - int:
isEven,isOdd,isNegative.
- List:
- A user
toString()is used by string interpolation andprint, also for
instances inside a List, Set or Map, and throughprint('$l'). - A
doubleprints as one (5.0) in the browser too, where JavaScript
formats a whole double without its.0. - Left-to-right evaluation.
a() + b()ranb()first.x += ereadsxbeforee.- Interpolation parts run in order:
'${c.b()} ${c.count}'readcount
beforeb().
staticfields. Concurrent first reads of a class'sstaticfields no
longer see a half-initialized store ('${C.n} ${C.s}'readnull). A
staticinitializer can read anotherstaticof its class
(static int b = C.a + 1;, or astatic final C instance = C();whose
constructor updatesC.count).- A receiver runs once.
make().bump(),make().bump().vand
make().gused to callmake()two to seven times. p == nullisfalsewithout calling a useroperator ==.- Spreading a
Map({...m}) is refused: map literals don't take spreads
yet, so{...m}silently built aSetof entries. - Other fixes:
s += '…$x'on aString, and compound assignment with adynamic
operand.- A
dynamic/varvalue keeps its class instance: afor (var p in l)
overList<P>lostp's class. h.fn(4)calls a function stored in the fieldfn.try { return g(); } catch …andtry { return 'ok ${g()}'; } catch …
catch whatg()throws.