Covariant return updates to ecma augments#56496
Conversation
| | C | C::VirtualFunction() | C::VirtualFunction | | ||
| " | ||
|
|
||
| Add a new paragraph "When a rules above result in the implementation of virtual method not satisfying the requirement that the signature of the implementor of a virtual method is not *covariant-return-compatible-with* (§I.8.7.1) the program is not considered well formed. As an example, this can happen if a virtual method is overriden with a .override directive(A) paired with a `PreserveBaseOverridesAttribute` with a *covariant-return-compatible-with* signature. and then the initial virtual method is subsequently overridden with a method which is *covariant-return-compatible-with* the initial virtual method, but not with the method body associated with .override directive(A)." |
There was a problem hiding this comment.
A nit "When a rules" -> "When rules"
There was a problem hiding this comment.
(or a rule even though I'm not sure whether there's a real difference between the singular and plural in this case)
There was a problem hiding this comment.
Actually, I think there's also a confusing double negative in the sentence unless I'm reading it wrong - "something results in the implementation of virtual method not satisfying that the signature of something is not covariant compatible", at the very least it's quite a bit to chew on which is the traditional hell of all specs :-).
| Add a new paragraph "When a rules above result in the implementation of virtual method not satisfying the requirement that the signature of the implementor of a virtual method is not *covariant-return-compatible-with* (§I.8.7.1) the program is not considered well formed. As an example, this can happen if a virtual method is overriden with a .override directive(A) paired with a `PreserveBaseOverridesAttribute` with a *covariant-return-compatible-with* signature. and then the initial virtual method is subsequently overridden with a method which is *covariant-return-compatible-with* the initial virtual method, but not with the method body associated with .override directive(A)." | ||
|
|
||
| ### II.22.27 | ||
| Edit rule 12 to specify that "The method isgnature defined by *MethodBody* shall match those defined by *MethodDeclaration* exactly if *MethodDeclaration* defines a method on an interface or be covariant-return-compatible-with* (§I.8.7.1) if *MethodDeclaration* represents a method on a class." No newline at end of file |
There was a problem hiding this comment.
Missing * in front of the covariant-return-compatible-with
| } | ||
| ``` | ||
|
|
||
| Covariant return methods can only be described through MethodImpl records, and as are only be applicable to methods on reference types. Methods on interfaces and value types are not supported. In addition the covariant override is only applicable for overriding methods also defined on a reference type. |
There was a problem hiding this comment.
"and as are only ..." - was it meant to be "and as such are only ..."?
trylek
left a comment
There was a problem hiding this comment.
Looks great to me modulo a few nits, thanks David!
|
|
||
| ### II.10.3.2 The .override directive (page 147) | ||
|
|
||
| Edit the first paragraph "The .override directive specifies that a virtual method shall be implemented (overridden), in this type, by a virtual method with a different name, but with a *covariant-return-compatible-with* signature (§I.8.7.1). This directive can be used to provide an implementation for a virtual method inherited from a base class, or a virtual method specified in an interface implemented by this type and all other. If not used to provide an implementation for a virtual method inherited from a base class the signature must be the identical." |
There was a problem hiding this comment.
Nit - "the signature must be the identical" - as you know I'm not a native English speaker but should this rather be the signature must be identical or alternatively the signature must be the same?
There was a problem hiding this comment.
Sigh. My reading tends to gloss over that sort of issue, which is why a non-English speaker is actually quite helpful in this kind of review as you don't do that. Yes. the signature must be identical sounds right to me.
|
|
||
| ### II.10.3.4 Impact of overrides on derived classes | ||
| Add a third bullet | ||
| "- If a virtual method is overridden via a .override directive and virtual method in parent class was overriden with a .override directive where the method body of that second .override directive is decorated with `System.Runtime.CompilerServices.PreserveBaseOverridesAttribute` then the virtual method override shall apply to the method body of the second .override directive as well. |
| | C | C::VirtualFunction() | C::VirtualFunction | | ||
| " | ||
|
|
||
| Add a new paragraph "When a rules above result in the implementation of virtual method not satisfying the requirement that the signature of the implementor of a virtual method is not *covariant-return-compatible-with* (§I.8.7.1) the program is not considered well formed. As an example, this can happen if a virtual method is overriden with a .override directive(A) paired with a `PreserveBaseOverridesAttribute` with a *covariant-return-compatible-with* signature. and then the initial virtual method is subsequently overridden with a method which is *covariant-return-compatible-with* the initial virtual method, but not with the method body associated with .override directive(A)." |
| | C | C::VirtualFunction() | C::VirtualFunction | | ||
| " | ||
|
|
||
| Add a new paragraph "When a rules above result in the implementation of virtual method not satisfying the requirement that the signature of the implementor of a virtual method is not *covariant-return-compatible-with* (§I.8.7.1) the program is not considered well formed. As an example, this can happen if a virtual method is overriden with a .override directive(A) paired with a `PreserveBaseOverridesAttribute` with a *covariant-return-compatible-with* signature. and then the initial virtual method is subsequently overridden with a method which is *covariant-return-compatible-with* the initial virtual method, but not with the method body associated with .override directive(A)." |
There was a problem hiding this comment.
(or a rule even though I'm not sure whether there's a real difference between the singular and plural in this case)
| | C | C::VirtualFunction() | C::VirtualFunction | | ||
| " | ||
|
|
||
| Add a new paragraph "When a rules above result in the implementation of virtual method not satisfying the requirement that the signature of the implementor of a virtual method is not *covariant-return-compatible-with* (§I.8.7.1) the program is not considered well formed. As an example, this can happen if a virtual method is overriden with a .override directive(A) paired with a `PreserveBaseOverridesAttribute` with a *covariant-return-compatible-with* signature. and then the initial virtual method is subsequently overridden with a method which is *covariant-return-compatible-with* the initial virtual method, but not with the method body associated with .override directive(A)." |
There was a problem hiding this comment.
Actually, I think there's also a confusing double negative in the sentence unless I'm reading it wrong - "something results in the implementation of virtual method not satisfying that the signature of something is not covariant compatible", at the very least it's quite a bit to chew on which is the traditional hell of all specs :-).
| } | ||
| ``` | ||
|
|
||
| Covariant return methods can only be described through MethodImpl records, and are only be applicable to methods on non-interface reference types. In addition the covariant override is only applicable for overriding methods also defined on a non-interface reference type. |
There was a problem hiding this comment.
One last: "are only be applicable" -> "are only applicable"
| | C | C::VirtualFunction() | C::VirtualFunction | | | ||
| | D | B::VirtualFunction() | ERROR | A program containing type D is not valid, as B::VirtualFunction would be implemented by D::VirtualFunction which is not *covariant-return-compatible-with* (§I.8.7.1) B::VirtualFunction | | ||
| " | ||
|
|
There was a problem hiding this comment.
Wow, I didn't expect such a profound effect on the wording, I really appreciate your diligence towards polishing the spec!
Update the ECMA augments file to reflect changes made in .NET 5.0 for covariant returns.
Fixes #37265
Fixes #43814