@@ -20,6 +20,8 @@ import java.util.NoSuchElementException
20
20
21
21
object TypeApplications {
22
22
23
+ type TypeParamInfo = ParamInfo .Of [TypeName ]
24
+
23
25
/** Assert type is not a TypeBounds instance and return it unchanged */
24
26
val noBounds = (tp : Type ) => tp match {
25
27
case tp : TypeBounds => throw new AssertionError (" no TypeBounds allowed" )
@@ -46,14 +48,14 @@ object TypeApplications {
46
48
47
49
/** Does the variance of type parameter `tparam1` conform to the variance of type parameter `tparam2`?
48
50
*/
49
- def varianceConforms (tparam1 : ParamInfo , tparam2 : ParamInfo )(implicit ctx : Context ): Boolean =
51
+ def varianceConforms (tparam1 : TypeParamInfo , tparam2 : TypeParamInfo )(implicit ctx : Context ): Boolean =
50
52
varianceConforms(tparam1.paramVariance, tparam2.paramVariance)
51
53
52
54
/** Do the variances of type parameters `tparams1` conform to the variances
53
55
* of corresponding type parameters `tparams2`?
54
56
* This is only the case of `tparams1` and `tparams2` have the same length.
55
57
*/
56
- def variancesConform (tparams1 : List [ParamInfo ], tparams2 : List [ParamInfo ])(implicit ctx : Context ): Boolean =
58
+ def variancesConform (tparams1 : List [TypeParamInfo ], tparams2 : List [TypeParamInfo ])(implicit ctx : Context ): Boolean =
57
59
tparams1.corresponds(tparams2)(varianceConforms)
58
60
59
61
/** Extractor for
@@ -72,7 +74,7 @@ object TypeApplications {
72
74
}
73
75
74
76
def unapply (tp : Type )(implicit ctx : Context ): Option [TypeRef ] = tp match {
75
- case tp @ PolyType (tparams, AppliedType (fn : TypeRef , args)) if (args == tparams.map(_.toArg)) => Some (fn)
77
+ case tp @ PolyType /* ### */ (tparams, AppliedType (fn : TypeRef , args)) if (args == tparams.map(_.toArg)) => Some (fn)
76
78
case _ => None
77
79
}
78
80
}
@@ -95,7 +97,7 @@ object TypeApplications {
95
97
refinements = rt :: refinements
96
98
tycon = rt.parent.stripTypeVar
97
99
}
98
- def collectArgs (tparams : List [ParamInfo ],
100
+ def collectArgs (tparams : List [TypeParamInfo ],
99
101
refinements : List [RefinedType ],
100
102
argBuf : mutable.ListBuffer [Type ]): Option [(Type , List [Type ])] = refinements match {
101
103
case Nil if tparams.isEmpty && argBuf.nonEmpty =>
@@ -116,7 +118,7 @@ object TypeApplications {
116
118
117
119
/** Adapt all arguments to possible higher-kinded type parameters using etaExpandIfHK
118
120
*/
119
- def EtaExpandIfHK (tparams : List [ParamInfo ], args : List [Type ])(implicit ctx : Context ): List [Type ] =
121
+ def EtaExpandIfHK (tparams : List [TypeParamInfo ], args : List [Type ])(implicit ctx : Context ): List [Type ] =
120
122
if (tparams.isEmpty) args
121
123
else args.zipWithConserve(tparams)((arg, tparam) => arg.EtaExpandIfHK (tparam.paramInfoOrCompleter))
122
124
@@ -159,7 +161,7 @@ object TypeApplications {
159
161
* result type. Using this mode, we can guarantee that `appliedTo` will never
160
162
* produce a higher-kinded application with a type lambda as type constructor.
161
163
*/
162
- class Reducer (tycon : PolyType , args : List [Type ])(implicit ctx : Context ) extends TypeMap {
164
+ class Reducer (tycon : TypeLambda , args : List [Type ])(implicit ctx : Context ) extends TypeMap {
163
165
private var available = (0 until args.length).toSet
164
166
var allReplaced = true
165
167
def hasWildcardArg (p : TypeParamRef ) =
@@ -208,11 +210,11 @@ class TypeApplications(val self: Type) extends AnyVal {
208
210
* with the bounds on its hk args. See `LambdaAbstract`, where these
209
211
* types get introduced, and see `isBoundedLambda` below for the test.
210
212
*/
211
- final def typeParams (implicit ctx : Context ): List [ParamInfo ] = /* >|>*/ track(" typeParams" ) /* <|<*/ {
213
+ final def typeParams (implicit ctx : Context ): List [TypeParamInfo ] = /* >|>*/ track(" typeParams" ) /* <|<*/ {
212
214
self match {
213
215
case self : ClassInfo =>
214
216
self.cls.typeParams
215
- case self : PolyType =>
217
+ case self : TypeLambda =>
216
218
self.typeParams
217
219
case self : TypeRef =>
218
220
val tsym = self.symbol
@@ -235,7 +237,7 @@ class TypeApplications(val self: Type) extends AnyVal {
235
237
}
236
238
237
239
/** If `self` is a higher-kinded type, its type parameters, otherwise Nil */
238
- final def hkTypeParams (implicit ctx : Context ): List [ParamInfo ] =
240
+ final def hkTypeParams (implicit ctx : Context ): List [TypeParamInfo ] =
239
241
if (isHK) typeParams else Nil
240
242
241
243
/** If `self` is a generic class, its type parameter symbols, otherwise Nil */
@@ -250,7 +252,7 @@ class TypeApplications(val self: Type) extends AnyVal {
250
252
def isHK (implicit ctx : Context ): Boolean = self.dealias match {
251
253
case self : TypeRef => self.info.isHK
252
254
case self : RefinedType => false
253
- case self : PolyType => true
255
+ case self : TypeLambda => true
254
256
case self : SingletonType => false
255
257
case self : TypeVar =>
256
258
// Using `origin` instead of `underlying`, as is done for typeParams,
@@ -273,16 +275,9 @@ class TypeApplications(val self: Type) extends AnyVal {
273
275
*
274
276
* type T[X] = U becomes type T = [X] -> U
275
277
* type T[X] >: L <: U becomes type T >: L <: ([X] -> U)
276
- *
277
- * TODO: Handle parameterized lower bounds
278
278
*/
279
- def LambdaAbstract (tparams : List [ParamInfo ])(implicit ctx : Context ): Type = {
280
- def nameWithVariance (tparam : ParamInfo ) =
281
- tparam.paramName.withVariance(tparam.paramVariance)
282
- def expand (tp : Type ) =
283
- PolyType (tparams.map(nameWithVariance))(
284
- tl => tparams.map(tparam => tl.lifted(tparams, tparam.paramInfo).bounds),
285
- tl => tl.lifted(tparams, tp))
279
+ def LambdaAbstract (tparams : List [TypeParamInfo ])(implicit ctx : Context ): Type = {
280
+ def expand (tp : Type ) = PolyType /* HKTypeLambda*/ .fromParams(tparams, tp)
286
281
if (tparams.isEmpty) self
287
282
else self match {
288
283
case self : TypeAlias =>
@@ -362,10 +357,10 @@ class TypeApplications(val self: Type) extends AnyVal {
362
357
if (hkParams.isEmpty) self
363
358
else {
364
359
def adaptArg (arg : Type ): Type = arg match {
365
- case arg @ PolyType (tparams, body) if
360
+ case arg @ PolyType (tparams, body) if /* ### */
366
361
! tparams.corresponds(hkParams)(_.paramVariance == _.paramVariance) &&
367
362
tparams.corresponds(hkParams)(varianceConforms) =>
368
- PolyType (
363
+ PolyType (/* ### */
369
364
(tparams, hkParams).zipped.map((tparam, hkparam) =>
370
365
tparam.paramName.withVariance(hkparam.paramVariance)))(
371
366
tl => arg.paramInfos.map(_.subst(arg, tl).bounds),
@@ -409,7 +404,7 @@ class TypeApplications(val self: Type) extends AnyVal {
409
404
val dealiased = stripped.safeDealias
410
405
if (args.isEmpty || ctx.erasedTypes) self
411
406
else dealiased match {
412
- case dealiased : PolyType =>
407
+ case dealiased : TypeLambda =>
413
408
def tryReduce =
414
409
if (! args.exists(_.isInstanceOf [TypeBounds ])) {
415
410
val followAlias = Config .simplifyApplications && {
0 commit comments