Skip to content

finish covariance checks for generic types #27259

Closed
@vsmenon

Description

@vsmenon

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

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onsoundnesstype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dev-compiler

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions