Closed JaffaKetchup closed 2 months ago
Describe the issue In a constant expression, the use of x % 2 == 0 is a valid constant expression (assuming x is const), however .isEven is not.
x % 2 == 0
.isEven
To Reproduce
Example 1:
void main() { const x = 1; const e = x % 2 == 0; // Working, lint thrown } void main() { const x = 1; const e = x.isEven; // Compilation error, lint not thrown }
Example 2:
class Example { const Example(int x) : assert(x % 2 == 0); // Working, lint thrown } class Example { const Example(int x) : assert(x.isEven); // Compilation error, lint not thrown }
Expected behavior use_is_even_rather_than_modulo should not be thrown when the surroundings are const.
use_is_even_rather_than_modulo
This may also apply to other lints that apply similar suggestions: they should all be const-aware.
const
Fixed with https://github.com/dart-lang/sdk/commit/4c888ab54cfb6be257351a225c9d157b12cfe692
Describe the issue In a constant expression, the use of
x % 2 == 0
is a valid constant expression (assuming x is const), however.isEven
is not.To Reproduce
Example 1:
Example 2:
Expected behavior
use_is_even_rather_than_modulo
should not be thrown when the surroundings are const.This may also apply to other lints that apply similar suggestions: they should all be
const
-aware.