Skip to content

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

@sgrekhov

Description

@sgrekhov

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"

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions