Skip to content

False prefer_const_constructors_in_immutables on class that can never be const constructed #58718

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
goderbauer opened this issue Apr 27, 2022 · 1 comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-false-positive linter-set-flutter P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@goderbauer
Copy link
Contributor

goderbauer commented Apr 27, 2022

The following code produces a misleading prefer_const_constructors_in_immutables lint:

@immutable
class Foo {
  Foo(this.list) : assert(list.length > 2); // prefer_const_constructors_in_immutables
  final List<int> list;
}

My understanding from flutter/flutter#102460 (comment) and dart-lang/language#1296 is that this class can never be const-constructed. So, suggesting to give it a const constructor is ... not helpful. :)

Instead, there should actually be the opposite warning: If you do make this constructor const, it should warn that this class can actually never be const constructed and that the const should be removed. I filed #58719 for that.

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jun 30, 2022
@srawlins srawlins added the P2 A bug or feature request we're likely to work on label Sep 27, 2022
@srawlins
Copy link
Member

srawlins commented Jul 8, 2024

Duplicate of #58360

@srawlins srawlins closed this as completed Jul 8, 2024
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
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. linter-false-positive linter-set-flutter P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants