@@ -54,18 +54,18 @@ object TypeApplications {
54
54
*/
55
55
object TypeLambda {
56
56
def apply (variances : List [Int ],
57
- argBoundss : List [TypeBounds ],
57
+ argBoundsFns : List [RefinedType => TypeBounds ],
58
58
bodyFn : RefinedType => Type )(implicit ctx : Context ): Type = {
59
- def argRefinements (parent : Type , i : Int , bs : List [TypeBounds ]): Type = bs match {
59
+ def argRefinements (parent : Type , i : Int , bs : List [RefinedType => TypeBounds ]): Type = bs match {
60
60
case b :: bs1 =>
61
61
argRefinements(RefinedType (parent, tpnme.hkArg(i), b), i + 1 , bs1)
62
62
case nil =>
63
63
parent
64
64
}
65
65
assert(variances.nonEmpty)
66
- assert(argBoundss .length == variances.length)
66
+ assert(argBoundsFns .length == variances.length)
67
67
RefinedType (
68
- argRefinements(defn.LambdaTrait (variances).typeRef, 0 , argBoundss ),
68
+ argRefinements(defn.LambdaTrait (variances).typeRef, 0 , argBoundsFns ),
69
69
tpnme.hkApply, bodyFn(_).bounds.withVariance(1 ))
70
70
}
71
71
@@ -94,7 +94,9 @@ object TypeApplications {
94
94
assert(tycon.isEtaExpandable)
95
95
val tparams = tycon.typeParams
96
96
val variances = tycon.typeParams.map(_.variance)
97
- TypeLambda (tparams.map(_.variance), tycon.paramBounds,
97
+ TypeLambda (
98
+ tparams.map(_.variance),
99
+ tycon.paramBounds.map(internalize(_, tycon.typeParams)),
98
100
rt => tycon.appliedTo(argRefs(rt, tparams.length)))
99
101
}
100
102
@@ -162,7 +164,11 @@ object TypeApplications {
162
164
}
163
165
}
164
166
165
- /** Adapt all arguments to possible higher-kinded type parameters using adaptIfHK
167
+ private def internalize [T <: Type ](tp : T , tparams : List [Symbol ])(implicit ctx : Context ) =
168
+ (rt : RefinedType ) =>
169
+ new ctx.SafeSubstMap (tparams, argRefs(rt, tparams.length)).apply(tp).asInstanceOf [T ]
170
+
171
+ /** Adapt all arguments to possible higher-kinded type parameters using adaptIfHK
166
172
*/
167
173
def adaptArgs (tparams : List [Symbol ], args : List [Type ])(implicit ctx : Context ): List [Type ] =
168
174
if (tparams.isEmpty) args
@@ -257,8 +263,10 @@ class TypeApplications(val self: Type) extends AnyVal {
257
263
*/
258
264
def LambdaAbstract (tparams : List [Symbol ])(implicit ctx : Context ): Type = {
259
265
def expand (tp : Type ) = {
260
- TypeLambda (tparams.map(_.variance), tparams.map(_.info.bounds),
261
- rt => new ctx.SafeSubstMap (tparams, argRefs(rt, tparams.length)).apply(tp))
266
+ TypeLambda (
267
+ tparams.map(_.variance),
268
+ tparams.map(tparam => internalize(tparam.info.bounds, tparams)),
269
+ internalize(tp, tparams))
262
270
}
263
271
self match {
264
272
case self : TypeAlias =>
0 commit comments