dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.09k stars 1.56k forks source link

[dart:html] Methods with generic type T return dynamic instead of T #40719

Open mdebbar opened 4 years ago

mdebbar commented 4 years ago

Repro:

It looks like PointerEvent.getCoalescedEvents() is annotated correctly in dart:html, and is supposed to return a List<PointerEvent>. But in reality, it returns a List<dynamic> and that throws off the runtime type checker.

cc @vsmenon @sigmundch

vsmenon commented 4 years ago

fyi - @srujzs @rakudrama

Some possibilities: (1) Change dart:html to List<dynamic> to reflect reality. (2) Change the python code to auto-tag (or cast) getters / methods that return List<T> where T is not top. (3) Handle in the compilers? (4) Wait for JsAny - that could be a while.

rakudrama commented 4 years ago

/cc @natebosch What is stopping us from doing (4)? Everything else is slower, more code, or a worse user experience.

natebosch commented 4 years ago

We should do (1) in the short term - it's consistent with other APIs in dart:html.

(2) Change the python code to auto-tag (or cast) getters / methods that return List<T> where T is not top.

I think the problem is that this introduced a performance overhead. .cast is often not the correct choice - List<T>.from is often better, but we can't make that decision ourselves since it depends on the usage patterns.

What is stopping us from doing (4)?

Time mostly. This is the long term goal but we don't have a concrete semantics proposal and don't know how long it will take to implement consistently between ddc and dart2js.

srujzs commented 4 years ago

Talked to @sigmundch about this and related changes for natives. We'd need to switch to dynamic wherever we're using native methods with generics, so I'm going to scope this bug appropriately to addressing wherever those instances are.

sigmundch commented 4 years ago

We'd need to switch to dynamic wherever we're using native methods with generics,

Just to avoid confusion, we meant a dynamic type variable (basically (1) above) anywhere where we return List<T>, Map<K, V>, etc