Skip to content

Warn if a class with const constructor can actually never be const constructed #58719

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
goderbauer opened this issue Apr 27, 2022 · 1 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

Comments

@goderbauer
Copy link
Contributor

My understanding from flutter/flutter#102460 (comment) and dart-lang/language#1296 is that the following class can actually never be const constructed.

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

To make this clear, the const should be removed from the constructor. Would it be possible to have a lint for that reminds people to not mark it as const?

@eernstg
Copy link
Member

eernstg commented Apr 28, 2022

dart-lang/language#1296 would actually make list.length in the assertion a compile-time error, so this issue could be considered to be a request for a lint in the case where dart-archive/linter#1296 is rejected.

Also note that dart-lang/language#2219 would introduce support for that expression, so it would just work.

@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
@pq pq added the P3 A lower priority bug or feature request label Nov 20, 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

5 participants