Skip to content

Unexpected unnecessary_cast when cast is required for argument type #49269

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

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
devexp-warning Issues with the analyzer's Warning codes legacy-area-analyzer Use area-devexp instead. 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 legacy-area-analyzer Use area-devexp instead. devexp-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
devexp-warning Issues with the analyzer's Warning codes legacy-area-analyzer Use area-devexp instead. 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