Skip to content

Strange inference with a ternary operator and Lists #24202

Closed
@nex3

Description

@nex3

On the following code:

void fn(Iterable iter) {}

void main() {
  bool condition = true;
  Iterable<String> iter = [];
  fn(condition ? [] : iter.toList());
}

The analyzer reports the following warning:

[warning] The argument type 'EfficientLength' cannot be assigned to the parameter type 'Iterable'

This seems wrong. The first branch of the ternary operator is a List, which is assignable to Iterable.

Note that if <String> is removed from the type annotation for iter, or if <String> is added to the list literal, the warning goes away.

I'm using 1.13.0-edge.9e18a7519d429f87c70bb3b8871c6cc666ee3fa6.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions