Skip to content

Implement support for dynamic checks on parameters that are covariant-by-declaration due to inheritance #47072

Closed
@eernstg

Description

@eernstg

Cf. dart-lang/language#925, consider the following program:

class A {}
class B extends A {}

class C {
  // The parameter `b` is not covariant-by-declaration as seen from here.
  void f(B b) {}
}

abstract class I {
  // If `I` is a superinterface of any class,
  // the parameter of its `f` is covariant-by-declaration.
  void f(covariant A a);
}

class D extends C implements I {} // OK.

void main() {
  I i = D();
  i.f(A()); // Dynamic type error.
}

The class D will behave in such a way that the actual argument to its f method has its type checked dynamically. In other words, when C.f is inherited by D, it is changed such that it's parameter is covariant-by-declaration. (This may be achieved by implicitly inducing a forwarding stub into D that calls super.f(...), but it could also be done by other means.)

This issue is concerned with the implementation of this feature. The tests added in https://dart-review.googlesource.com/c/sdk/+/208504 can be used as a guide.

This is not tied to a language version or a flag, because it only allows programs with errors to become running programs.

Subtasks:

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onarea-metaCross-cutting, high-level issues (for tracking many other implementation issues, ...).implementationTrack the implementation of a specific feature (use on area-meta issue, not issues for each tool)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions