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.22k stars 1.57k forks source link

[dart2js] bug in global inference with `call` getter #56293

Closed sigmundch closed 3 months ago

sigmundch commented 3 months ago

This is a reduction from https://github.com/flutter/flutter/issues/151978

It appears that global type inference doesn't properly trace a closure invocation when the closure is stored in a field named call. For example:

class B {
  final void Function(Object?) call;
  final void Function(Object?) call2;
  B(this.call, this.call2);
}

f1(Object? o) => print(o == null);
f2(Object? o) => print(o == null);

void main() {
  B(f1, f2).call(null);
  B(f1, f2).call2(null);
}

This program should print true twice, but currently prints false on the first case when using the call getter`. Disabling global type inference does make this print true as it should.

dart-github-bot commented 3 months ago

Summary: Global type inference fails to correctly infer the type of a closure invoked through a field named call, leading to incorrect type checks and unexpected behavior. This issue manifests when using the call getter and can be resolved by disabling global type inference.