Dart 2 type system

70 views
Skip to first unread message

Nils Döhring

unread,
May 9, 2018, 5:39:16 AM5/9/18
to StageXL
Hey Bernhard and fellow StageXL contributors,

As of Dart SDK 2.0.0-dev.53.0, dartdevc's (dart2js respectively) default settings will use the Dart 2 type system, which results in StageXL's event engine producing errors at runtime. 

Example

 Sprite p = new Sprite();
 p
.graphics.rect(0, 0, 200, 50);
 p
.graphics.fillColor(Color.Red);
 p
.addEventListener<MouseEvent>(MouseEvent.MOUSE_DOWN, _onSubmit);
 stage
.addChild(p);



void _onSubmit(MouseEvent e) {
 
print("submitted");
}

Result: Type '(MouseEvent) => void' is not a subtype of type '(Event) => void' in strong mode

This listener will work, though:

void _onSubmit(Event e) {
 
MouseEvent me = e as MouseEvent;
 
print("test: ${me.localX}");
}

Now, unfortunately, debugging Dart 2 is still hard, so that currently I can only assume that the culprit is either in EventDispatcher's dispatchEvent and dispatchEventRaw, or it's a bug in Dart 2 – because I would think that MouseEvent is a subtype of Event.

Long story short: 
- Any of you guys have an explanation? 
- Any of you working on migrating StageXL to Dart 2? 
-- If not, I guess I'll be able find time to take a first shot at it these days.

Thanks,
Nils

Bernhard Pichler

unread,
May 12, 2018, 4:32:22 AM5/12/18
to StageXL
Hi,

I was wondering about this error message before and i don't get it. 

Kevin Moore from the Dart team did a few pull requests to adapt StageXL to the new type system of Dart 2. I didn't took a closer look since it is very unclear when there will be a final version of Dart 2 for the web. Do you have any information about this? Everything seems to be focus on Flutter and there is very little information about the web, which is very unfortunate.

Maybe the thing with the MouseEvent / Event thing because you have to declare that it is a covariant type when you pass it to a callback (event listener). I think i saw somewhere that you can declare this in Dart 2 but i can't remember where i saw it. It was also early days of Dart 2 and many things have chance since.

Anyhow, if you could take a look at this a pull request would be welcome of course.

Thanks,
Bernhard

Bernhard Pichler

unread,
May 12, 2018, 4:45:31 AM5/12/18
to StageXL
Here they are talking about the covariant feature - but i have no idea if this is really the problem.

Nils Döhring

unread,
May 12, 2018, 12:09:47 PM5/12/18
to StageXL
Hmm, not sure, it looks like covariant is about making overriding more flexible, which is not the use case here.

While thanks to kevmoo's PRs, StageXL is compatible with the --preview-dart-2 feature of STABLE (v1.x), but as of v2.0.0-dev53.0, the new build system now sets ignore_cast_failures to false by default, breaking each and any StageXL project (it took me an hour to find the place where to override the default). 

That said, I don't have info on the Dart 2 roadmap, and yes, webdev progress is currently largely undocumented. I have been able to put together a project that builds and runs successfully on bleeding edge v2 DEV:
It requires the most recent IDEA (or WebStorm EAP) 2018.1.3 for debugging to work. 

Currently, there's two bugs keeping me from digging deeper into the cast failures:
- in IDEA, breakpoints in 3rd party packages aren't hit (fix will land in 2018.2)
- the debugger's stack trace currently only links to generated JS source

Next steps:
- I have summoned kevmoo – he might be interested in helping to fix this because his pop-pop-win sample has stopped working, too :-)
- I'll also create a fork of StageXL, add a small example directly, enable the Dart 2 build and type system, and move on from there.

Best,
Nils


Message has been deleted

Nils Döhring

unread,
May 12, 2018, 7:05:26 PM5/12/18
to StageXL
For the record: Cast failures just have been fixed.

Tyler Turner

unread,
May 16, 2018, 11:48:30 PM5/16/18
to StageXL
Thanks for the update!
Reply all
Reply to author
Forward
0 new messages