Skip to content

[cfe] Extension on type void can be called #57082

@sgrekhov

Description

@sgrekhov

According to the extension methods specification

It is a compile-time error if the static type of the argument expression (expr) of an explicit extension invocation is void. (Expressions of type void are only allowed in a few specific syntactic positions, and the new explicit extension invocation object position is not included in those.)

But the following code produces an error in the analyzer but no any issues in CFE

extension ExtVoid on void {
  void checkme() {
    print("I'm extension");
  }
}

main() {
  ExtVoid(print("print() returns void")).checkme(); // Analyzer error. use_of_void_result
}

When run this program prints I'm extension. But there should be a compile-time error.

Dart SDK version: 3.7.0-123.0.dev (dev) (Fri Nov 8 08:06:44 2024 -0800) on "windows_x64"

Metadata

Metadata

Labels

cfe-dysfunctionalitiesIssues for the CFE not behaving as intendedlegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions