Skip to content

Rule Req: recommend using a base type instead of var when LUB applies #57606

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

Open
robbecker-wf opened this issue Jul 11, 2017 · 4 comments
Open
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-lint-request P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@robbecker-wf
Copy link

I would like to get a lint warning/hint for ternary operators when encountering code like this:

A -> SubClass1 -> BaseClass, with Element -> Object
B -> SubClass2 -> BaseClass, with Element -> Object

var shouldBeOfTypeBaseClass = someBoolCheck() ? new A() : new B();
// the analyzer will infer that shouldBeOfTypeBaseClass is of type Object instead of the 
// desired `BaseClass` class

// the same thing would apply to the ?? operator
A a;
B b = new B();
var shouldBeOfTypeBaseClass = a ?? b;

See #30079 (comment) for more info on motivation.

I'd like to see a lint warning on the var before shouldBeOfTypeBaseClass pointing out that the type of shouldBeOfTypeBaseClass will be inferred as Object and you should specify a base class type instead of using var.

@bwilkerson
Copy link
Member

@leafpetersen Another data point to consider when looking at LUB.

@alexeieleusis
Copy link
Contributor

What does LUB stands for?

@zoechi
Copy link
Contributor

zoechi commented Jul 20, 2017

Least Upper Bound dart-archive/dev_compiler#288

@leafpetersen
Copy link
Member

Noted.

@pq pq added type-enhancement A request for a change that isn't a bug linter-lint-request labels Jun 29, 2018
@srawlins srawlins added the P3 A lower priority bug or feature request label May 22, 2023
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-lint-request P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

8 participants