Add declaration-site variance feature specification - #1230
Conversation
9b92852 to
b944a7b
Compare
|
@eernstg What's the status of this PR? Could we merge this into the language repo? |
|
@kallentu wrote:
I haven't worked on this PR recently, but it could be useful to make sure it is up to date and then use that during the subsequent finalization of the feature. @leafpetersen, WDYT? Do you want to start afresh on a specification of declaration-site variance, or do we proceed to do it based on this PR? |
|
I think this specification can probably be used as the basis. My biggest worry is how to migrate platform libraries. If we can't make We need some migration path that allows adding restrictions to platform libraries. |
5b1e3c6 to
6157eb2
Compare
|
We're moving on this one! 🎉 I'll land this document now. Leaf and I talked about a couple of questions in need of further discussion, and they're on the language team agenda for the next meeting. Further discussions and revisions will occur as needed. |
| - **Interface Compositionality**: `T0` is an interface type or an extension | ||
| type `C0<S0, ..., Sk>` and `T1` is `C0<U0, ..., Uk>`. For `i` in `0..k`, | ||
| let `vi` be the declared variance of the `i`th type parameter of | ||
| `C0`. Then, for each `i` in `0..k`, one of the following holds: |
There was a problem hiding this comment.
Should this sentence be "Then, T0 <: T1 if and only if for each ..."? I feel like it's missing what these conditions define.
|
|
||
| It is a compile-time error if a variance modifier is specified for a type | ||
| parameter declared in the type parameter list of a declaration of an | ||
| extension, a generic function or method, an extension type, or a type |
There was a problem hiding this comment.
At the top, it says
The explicitly declared variance can be used with [...], that is, class, mixin class,
enum, extension type, and mixin declarations.
Here, it says that It's a compile time error with extension types.
Should they be removed from one of the lists?
This PR adds a feature specification for declaration-site variance, which is a sound and explicit mechanism for specifying that a type parameter of a generic class can be covariant (marked by
out), invariant (inout), or contravariant (in), cf. #524.