@@ -15,6 +15,7 @@ import util.Spans._
15
15
import util .Property
16
16
import collection .mutable
17
17
import tpd .ListOfTreeDecorator
18
+ import Variances .alwaysInvariant
18
19
import config .{Config , Feature }
19
20
import config .Printers .typr
20
21
import Annotations ._
@@ -968,7 +969,10 @@ class Namer { typer: Typer =>
968
969
override final def typeSig (sym : Symbol ): Type =
969
970
val tparamSyms = completerTypeParams(sym)(ictx)
970
971
given ctx as Context = nestedCtx
971
- def abstracted (tp : TypeBounds ): TypeBounds = HKTypeLambda .boundsFromParams(tparamSyms, tp)
972
+
973
+ def abstracted (tp : TypeBounds ): TypeBounds =
974
+ HKTypeLambda .boundsFromParams(tparamSyms, tp)
975
+
972
976
val dummyInfo1 = abstracted(TypeBounds .empty)
973
977
sym.info = dummyInfo1
974
978
sym.setFlag(Provisional )
@@ -998,8 +1002,20 @@ class Namer { typer: Typer =>
998
1002
}
999
1003
sym.info = dummyInfo2
1000
1004
1005
+ // If this type does not have type parameters itself, treat the parameters
1006
+ // of a type lambda on the RHS as non-variant. E.g.
1007
+ // type F <: [X] =>> G and type F[X] <: G
1008
+ // are treated alike.
1009
+ def addVariances (tp : Type ): Type = tp match
1010
+ case tp @ TypeBounds (lo, hi) =>
1011
+ tp.derivedTypeBounds(addVariances(lo), addVariances(hi))
1012
+ case tp : HKTypeLambda if tparamSyms.isEmpty && ! tp.isDeclaredVarianceLambda =>
1013
+ tp.withVariances(tp.paramNames.map(alwaysInvariant))
1014
+ case _ =>
1015
+ tp
1016
+
1001
1017
val rhs1 = typedAheadType(rhs)
1002
- val rhsBodyType : TypeBounds = rhs1.tpe.toBounds
1018
+ val rhsBodyType : TypeBounds = addVariances( rhs1.tpe) .toBounds
1003
1019
val unsafeInfo = if (isDerived) rhsBodyType else abstracted(rhsBodyType)
1004
1020
1005
1021
def opaqueToBounds (info : Type ): Type =
0 commit comments