Closed
Description
From @jmesserly on May 1, 2015 20:9
we need to add covariance checks for parameters, e.g. List<E>.add
... given
class Foo<T> {
T _t;
add(T t) {
_t = t;
}
forEach(void fn(T t)) {
// No check needed for `fn`
fn(_t);
}
}
class Bar extends Foo<int> {
add(int x) {
print('Bar.add got $x');
super.add(x);
}
}
main() {
Foo<Object> foo = new Bar();
foo.add('hi'); // should throw
}
currently I'm adding something simple to JS codegen, but it adds extra checks (Foo.forEach) and it misses checks (Bar.add). Also ideally we'd compute this earlier, in checker/coercion reifier.
Copied from original issue: dart-archive/dev_compiler#161