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

unnecessary_cast false positive with ternary operator when casting a List to an Iterable #49550

Closed
DetachHead opened this issue Jul 28, 2022 · 0 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. 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

@DetachHead
Copy link

void main(final List<String> value) {
  final foo = value.isEmpty
      ? ([value[0]] as Iterable<String>) //warning: Unnecessary cast.
      : [value].map((final value) => value);
  foo.map;
}

when removing the cast:

void main(final List<String> value) {
  final foo = value.isEmpty
      ? [value[0]]
      : [value].map((final value) => value);
  foo.map; //error: The getter 'map' isn't defined for the type 'Object'
}
@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 28, 2022
@keertip keertip added the P2 A bug or feature request we're likely to work on label Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. 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