Closed
Description
(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 namedcall
. In the case where the context type for e
is a function type or the typeFunction
, 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.