google / perf_api.dart

Apache License 2.0
8 stars 19 forks source link

Illegal field initializer in class Profiler #5

Open mhausner opened 10 years ago

mhausner commented 10 years ago

Class Profiler has a const constructor, yet its field 'counters' is initialized with 'new Counters()'. The language has recently changed and non-const initializers are no longer legal in classes that have a const constructor.

Dart2js has had this restriction even before it became part of the spec. I'm not sure how this code ran under dart2js.

class Profiler { final Counters counters = new Counters(); <<< illegal due to const constructor below.

/**

mhausner commented 10 years ago

See also issue #4. This is essentially a duplicate.

mhausner commented 10 years ago

And, answering my own question/doubt: dart2js only reports the illegal field initializer if the const constructor is called via the const operator, but not when it's called via the new operator. That's a dart2js bug. (dartbug.com/20378).