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 unnecessary_parenthesis #4871

Closed
JaffaKetchup opened this issue Feb 7, 2024 · 4 comments
Closed

False positive for unnecessary_parenthesis #4871

JaffaKetchup opened this issue Feb 7, 2024 · 4 comments
Assignees
Labels
false-positive 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

@JaffaKetchup
Copy link

JaffaKetchup commented Feb 7, 2024

Describe the issue
Given a class with a non-nullable field, and a constructor with a nullable equivalent, and without a default value (because the wanted default would be non-const), an initialiser list with a default is required to prevent an error.
However, if this relies around a function callback, such as type void Function(), defining a default function with the arrow syntax is impossible without producing either an error or a lint warning.

image
image
image

To Reproduce

// Valid, but false positive lint
class Example {
  final bool Function() e;

  Example({
    bool Function()? e,
  }) : e = e ??= (() => true);
}

// Throws error
class Example2 {
  final bool Function() e;

  Example2({
    bool Function()? e,
  }) : e = e ??= () => true;
}

Expected behavior
Unnecessary parenthesis lint should not be thrown, as the brackets are necessary.

Additional context
The suggested fix that removes the brackets causes the issue shown in image 2 & 3.

@srawlins
Copy link
Member

srawlins commented Feb 7, 2024

Thanks for filing an issue. Please provide a minimal, complete, reproduction (not screenshots).

@JaffaKetchup
Copy link
Author

@srawlins Of course, apologies. I've updated the original post.

@srawlins
Copy link
Member

srawlins commented Feb 7, 2024

Great catch! I'll note that I think the ??= should be ??. But I think still a valid bug.

@bwilkerson bwilkerson added false-positive P2 A bug or feature request we're likely to work on labels Feb 9, 2024
@srawlins srawlins self-assigned this Feb 15, 2024
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Feb 16, 2024
Fixes dart-lang/linter#4871

Change-Id: Id294bd4cbfd5af22d9201509210664fb16c31616
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352965
Auto-Submit: Samuel Rawlins <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Phil Quitslund <[email protected]>
@srawlins
Copy link
Member

Fixed by https://dart-review.googlesource.com/c/sdk/+/352965

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive 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

3 participants