File tree 1 file changed +13
-2
lines changed
compiler/src/dotty/tools/dotc/core
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -3713,8 +3713,19 @@ object Types {
3713
3713
tp match {
3714
3714
case tp : NamedType =>
3715
3715
if (stopAtStatic && tp.symbol.isStatic) tp
3716
- else derivedSelect(tp, this (tp.prefix))
3717
-
3716
+ else {
3717
+ val saved = variance
3718
+ variance = variance max 0
3719
+ // A prefix is never contravariant. Even if say `p.A` is used in a contravariant
3720
+ // context, we cannot assume contravariance for `p` because `p`'s lower
3721
+ // bound might not have a binding for `A` (e.g. the lower bound could be `Nothing`).
3722
+ // By contrast, covariance does translate to the prefix, since we have that
3723
+ // if `p <: q` then `p.A <: q.A`, and well-formedness requires that `A` is a member
3724
+ // of `p`'s upper bound.
3725
+ val prefix1 = this (tp.prefix)
3726
+ variance = saved
3727
+ derivedSelect(tp, prefix1)
3728
+ }
3718
3729
case _ : ThisType
3719
3730
| _ : BoundType
3720
3731
| NoPrefix => tp
You can’t perform that action at this time.
0 commit comments