Skip to content

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

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
DetachHead opened this issue Jul 28, 2022 · 0 comments
Labels
legacy-area-analyzer Use area-devexp instead. 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'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. 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