Closed
Description
The following ill-typed code:
void f(List<String> x, List<String> y) {
x.addAll(y.map((String z) => 1.0));
}
produces the strong mode warning Unsound implicit cast from Iterable<dynamic> to Iterable<String>
.
This is confusing because there's nothing dynamic in the above code. I would expect one of the following behaviors:
(String z) => 1.0
is inferred to have type(String) -> double
, thereforey.map((String z) => 1.0)
is inferred to have typeIterable<double>
, butx.addAll
requiresIterable<String>
, therefore the message isUnsound implicit cast from Iterable<double> to Iterable<String>
.- Since
x.addAll
requiresIterable<String>
, the type argument toy.map
is inferred to beString
, thereforey.map
requires type(String) -> String
. But the type of(String z) => 1.0
is(String) -> double
, therefore the message isunsound implicit cast from (String) -> double to (String) -> String
.
Activity