-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.linter-false-negativeIssues related to lint rules that fail to report a problem.Issues related to lint rules that fail to report a problem.triage-automationSee https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
Description
Describe the issue
unnecessary_parenthesis false negative.
When having a code like:
T a<T>(int x, bool test) {
switch (x) {
case 0:
return test ? 1 : 2 as T;
default:
return 3 as T;
}
}The return of case 0 warns: A value of type 'Object?' can't be returned from the function 'a' because it has a return type of 'T'.
So in that case, we need to wrap that in parentheses.
return (test ? 1 : 2) as T;This doesn't throw anymore.
When changing to the new pattern switch syntax, we can cast at the end as follows:
T a<T>(int x, bool test) {
return switch (x) {
0 => (test ? 1 : 2), // Not triggering
_ => 3,
} as T;
}And now that is not needed anymore and should trigger the lint.
Metadata
Metadata
Assignees
Labels
P2A bug or feature request we're likely to work onA bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.Use area-devexp instead.linter-false-negativeIssues related to lint rules that fail to report a problem.Issues related to lint rules that fail to report a problem.triage-automationSee https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)