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

Extension getter/setter prevents error from being reported for missing setter/getter on function type #57002

Open stereotype441 opened 15 hours ago

stereotype441 commented 15 hours ago

The analyzer accepts the following code, but the CFE rejects it:

extension on Object? {
  int get foo => 0;
}

test(void Function() f) {
  f.foo = 0; // ERROR
}

The CFE is correct in rejecting the code; there is no .foo= setter defined for the type void Function().

A similar thing happens with the roles of the getter and setter reversed. Again, the analyzer accepts the code, but the CFE rejects it:


extension on Object? {
  set foo(int value) {}
}

test(void Function() f) => f.foo; // ERROR
``
Again, the CFE is correct in rejecting the code.
stereotype441 commented 15 hours ago

I'm going to work on this.