Skip to content

Ensure analyzer allows desugaring iterable of callable type in for-each to a function type #47471

Closed
@srawlins

Description

@srawlins

(Analyzer allows this too)

Take this program:

class C {
  void call() {}
}

void foo(Iterable<C> iterable, C c) {
  for (void Function() f in [c /*1*/]) { // This makes sense
    f;
  }

  for (void Function() f in iterable) { // Why is this allowed?
    f;
  }
}

void main() {
  foo([C(), C()], C());
}

The spec says:

Let e be an expression whose static type is an interface
type that has a method named call. In the case where the context type for e
is a function type or the type Function, e is treated as e.call.

I understand why the first is allowed: c /*1*/ has a static type which is an interface type with a call method, and a context type which is a function type.

I don't understand why the second is allowed. In void Function() f in iterable, there is no expression whose static type is an interface type that has a method named call.

Analyzer allows this too but I'm considering it a bug that should be fixed.

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