Skip to content

CFE incorrectly rejects null-aware extension method invocation having type voidΒ #59690

@stereotype441

Description

@stereotype441

The following code is accepted by the anaylzer but rejected by the CFE:

class C {
  int f() => 0;
}

extension E on int {
  void f() {}
}

void test(int? i) {
  E(i)?.f();
}

main() {}

The CFE's error message is:

../../tmp/proj/test.dart:10:9: Error: This expression has type 'void' and can't be used.
  E(i)?.f();
        ^

The analyzer is correct; there shuld be no error.

Note however that there should be an error if the return value is actually used, e.g., if the contents of test were changed to print(E(i)?.f());.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions