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

Unexpected unnecessary_cast when cast is required for argument type #49269

Closed
natebosch opened this issue Jun 15, 2022 · 1 comment
Closed

Unexpected unnecessary_cast when cast is required for argument type #49269

natebosch opened this issue Jun 15, 2022 · 1 comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@natebosch
Copy link
Member

String takeNullable(Iterable<String>? i) => takeIterable(i ?? []); // Object can't be assigned to Iterable<Object>
String takeIterable(Iterable<Object> i) => '';
String takeNullable(Iterable<String>? i) => takeIterable((i ?? []) as Iterable<Object>); // unnecessary_cast
String takeIterable(Iterable<Object> i) => '';

This cast is necessary. Using a different pattern requires changing from => to {return}.

@natebosch natebosch added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes bug labels Jun 15, 2022
@natebosch
Copy link
Member Author

I think the cast should become unnecessary if we implemented dart-lang/language#2259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. 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

3 participants