Skip to content

Commit cdb928c

Browse files
Update subtype constraint generation to account for the "variance" feature. (#2152)
1 parent c504a1a commit cdb928c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

resources/type-system/inference.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,20 @@ clauses need be tried.
814814
- Note that we have already eliminated the case that `X` is a variable in
815815
`L`.
816816

817-
- If `P` is `C<M0, ..., Mk>` and `Q` is `C<N0, ..., Nk>`, then the match holds
818-
under constraints `C0 + ... + Ck`:
819-
- If `Mi` is a subtype match for `Ni` with respect to `L` under constraints
820-
`Ci`.
817+
- If `P` is `C<M0, ..., Mk>` and `Q` is `C<N0, ..., Nk>`, and the corresponding
818+
type parameters declared by the class `C` are `T0, ..., Tk`, then the match
819+
holds under constraints `C0 + ... + Ck`, if for each `i`:
820+
- If `Ti` is a **covariant** type variable, and `Mi` is a subtype match for
821+
`Ni` with respect to `L` under constraints `Ci`,
822+
- Or `Ti` is a **contravariant** type variable, `Ni` is a subtype match for
823+
`Mi` with respect to `L` under constraints `Ci`,
824+
- Or `Ti` is an **invariant** type variable, and:
825+
- `Mi` is a subtype match for `Ni` with respect to `L` under constraints
826+
`Ci0`,
827+
- And `Ni` is a subtype match for `Mi` with respect to `L` under constraints
828+
`Ci1`,
829+
- And `Ci` is `Ci0 + Ci1`.
830+
821831
- If `P` is `C0<M0, ..., Mk>` and `Q` is `C1<N0, ..., Nj>` then the match holds
822832
with respect to `L` under constraints `C`:
823833
- If `C1<B0, ..., Bj>` is a superinterface of `C0<M0, ..., Mk>` and `C1<B0,

0 commit comments

Comments
 (0)