Skip to content

Fix false positives in "Prefer finals over getters" rule. #57183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pq opened this issue Feb 18, 2015 · 3 comments
Closed

Fix false positives in "Prefer finals over getters" rule. #57183

pq opened this issue Feb 18, 2015 · 3 comments
Assignees
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@pq
Copy link
Member

pq commented Feb 18, 2015

As @zoechi pointed out on #57169, we need to refine our check to ensure we don't flag cases where the field is written to outside a constructor initializer.

In other words, this should produce a lint:

class A {
  var _a;
  var get a => _a; //LINT
  A(this._a);
}

But this should not:

class A {
  var _a;
  var get a => _a; //OK!
  A() {
    _init();
  }

  _init() {
   _a = 42;
  }
}
@pq pq added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Feb 18, 2015
@pq pq self-assigned this Feb 18, 2015
@xxgreg
Copy link

xxgreg commented Feb 26, 2015

Given library based privacy, I assume you'll also need to check that _a is not set from anywhere in the library, not just from within the class as in the example above.

library foo;
part 'other.dart';
class A {
   var _a;
}

other.dart:

part of foo;
foo(bar) {
  bar._a = 'oi!';
}

Also will there be a way to disable the lint if mirrors are used? (Another tricky case to consider is if generalised tear offs land)

@pq
Copy link
Member Author

pq commented Mar 16, 2015

@xxgreg 👍

I started implementing this for real today and got far enough along to decide to disable it in the meantime.

Thanks for chiming in!

@pq
Copy link
Member Author

pq commented Mar 16, 2015

Re-opened #57169. Tracking progress there.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants