-
Notifications
You must be signed in to change notification settings - Fork 213
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… an inherited method must be covariant-by-declaration, but is not
This was referenced Jul 8, 2021
lrhn
reviewed
Jul 8, 2021
Made some adjustments, PTAL. |
lrhn
approved these changes
Jul 9, 2021
Rewrote several parts of 'Correct Member Overrides', PTAL. |
lrhn
reviewed
Jul 9, 2021
…r a forwarding method in commentary
… need for a forwarding method in commentary" This reverts commit c315c9a.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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):
Here,
C
is an error because its interface has a member signaturenum foo(covariant num)
, but it has an implementation with signaturenum foo(num)
(inherited fromA
), and thecovariant
property is missing. (Note that we're talking about member signatures, andcovariant
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 byC
.