Skip to content

Clarify override error for inherited member with non-covariant parameter #1729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 14, 2021

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Jul 8, 2021

This PR updates the language specification to make it explicit that it is a compile-time error for a member signature m to override another member signature m2 if the latter has a parameter which is covariant-by-declaration, and the former does not have that.

This error is independent of the function types of the method signatures, so let's consider an example where the function types are identical (so it's trivially a correct member override in that respect):

class A { num foo(num n) => 1.1; }
abstract class B { num foo(covariant num x); }
class C extends A with B {} // Error

Here, C is an error because its interface has a member signature num foo(covariant num), but it has an implementation with signature num foo(num) (inherited from A), and the covariant property is missing. (Note that we're talking about member signatures, and covariant is always explicit in a member signature, as opposed to syntactic declarations where it may be present implicitly, because it is present in a superinterface.)

The point is that the inherited method implementation A.foo doesn't "magically" get a parameter which is covariant-by-declaration just because it's inherited by C.

… an inherited method must be covariant-by-declaration, but is not
@eernstg
Copy link
Member Author

eernstg commented Jul 9, 2021

Made some adjustments, PTAL.

@eernstg
Copy link
Member Author

eernstg commented Jul 9, 2021

Rewrote several parts of 'Correct Member Overrides', PTAL.

@eernstg eernstg merged commit 34b4a7f into master Jul 14, 2021
@eernstg eernstg deleted the fix_covariant_override_jul21 branch July 14, 2021 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants