Skip to content
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

False positive for use_is_even_rather_than_modulo #4915

Closed
JaffaKetchup opened this issue Mar 19, 2024 · 1 comment
Closed

False positive for use_is_even_rather_than_modulo #4915

JaffaKetchup opened this issue Mar 19, 2024 · 1 comment
Assignees
Labels
false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@JaffaKetchup
Copy link

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:

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.

This may also apply to other lints that apply similar suggestions: they should all be const-aware.

@srawlins srawlins added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P3 A lower priority bug or feature request false-positive labels Mar 19, 2024
@srawlins srawlins self-assigned this Apr 26, 2024
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Apr 26, 2024
Fixes dart-lang/linter#4915

Change-Id: I4b353b3f8cc064d15bbe366c9008c9a2fc1e1144
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364620
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
@srawlins
Copy link
Member

Fixed with dart-lang/sdk@4c888ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants