sdk icon indicating copy to clipboard operation
sdk copied to clipboard

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

Open DetachHead opened this issue 3 years ago • 0 comments

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'
}

DetachHead avatar Jul 28 '22 10:07 DetachHead