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.31k stars 1.59k forks source link

`parameter_assignments` false negative for anonymous functions and constructors #58659

Open Giuspepe opened 2 years ago

Giuspepe commented 2 years ago

Describe the issue The lint parameter_assignments does not work with anonymous functions.

To Reproduce

void main(){
    // `parameter_assignments` works fine with named functions
    void foo(int i) {
      i = 42; // LINT: `parameter_assignments`
      print(i);
    }
    foo(0);

    // `parameter_assignments` does not work with anonymous functions
    (int i) {
      i = 42; // false negative: should yield lint but doesn't!
      print(i);
    }(0);
}

Expected behavior The lint parameter_assignments should work with anonymous functions as well.

spkersten commented 1 year ago

There's also no warning for constructors:

class Foo {
  Foo(int x) {
    x = 4;
  }
}