File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -3713,8 +3713,19 @@ object Types {
37133713 tp match {
37143714 case tp : NamedType =>
37153715 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+ }
37183729 case _ : ThisType
37193730 | _ : BoundType
37203731 | NoPrefix => tp
You can’t perform that action at this time.
0 commit comments