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.28k stars 1.58k forks source link

[CFE] Type `void` and null-aware selector issue #57070

Open sgrekhov opened 1 week ago

sgrekhov commented 1 week ago

The code below produces no issues in the analyzer but an error in CFE.

class C<T> {
  T t;
  C(this.t);
}

main() {
  C<void> c1 = C<void>(1);
  C<void>? c2 = (2 > 1) ? C<void>(2) : null;
  print(c1.t as int); // prints 1
  print(c2?.t as int); // Error: This expression has type 'void' and can't be used.
}

Accoding to the spec

In a type cast e as T, e may have type void

There should be no such error in the CFE.

`Dart SDK version: 3.7.0-edge.a0c4efddb8ada994c3f8568268478a4948bc32b7 (main) (Tue Nov 12 08:16:42 2024 +0000) on "linux_x64"