@@ -515,26 +515,28 @@ class TypeApplications(val self: Type) extends AnyVal {
515
515
self.appliedTo(tparams map (_.typeRef)).LambdaAbstract (tparams)
516
516
}
517
517
518
- /** Test whether this type if od the form `B[T1, ..., Tn]`, or,
519
- * if `canWiden` if true, has a base type of the form `B[T1, ..., Bn]` where the type parameters
520
- * of `B` match one-by-one the variances of `tparams`, and where the lambda
521
- * abstracted type
518
+ /** Test whether this type has a base type of the form `B[T1, ..., Bn]` where
519
+ * the type parameters of `B` match one-by-one the variances of `tparams`,
520
+ * and where the lambda abstracted type
522
521
*
523
522
* LambdaXYZ { type Apply = B[$hkArg$0, ..., $hkArg$n] }
524
523
* { type $hkArg$0 = T1; ...; type $hkArg$n = Tn }
525
524
*
526
525
* satisfies predicate `p`. Try base types in the order of their occurrence in `baseClasses`.
527
526
* A type parameter matches a variance V if it has V as its variance or if V == 0.
527
+ * @param classBounds A hint to bound the search. Only types that derive from one of the
528
+ * classes in classBounds are considered.
528
529
*/
529
- def testLifted (tparams : List [Symbol ], p : Type => Boolean , canWiden : Boolean )(implicit ctx : Context ): Boolean = {
530
+ def testLifted (tparams : List [Symbol ], p : Type => Boolean , classBounds : List [ ClassSymbol ] )(implicit ctx : Context ): Boolean = {
530
531
def tryLift (bcs : List [ClassSymbol ]): Boolean = bcs match {
531
532
case bc :: bcs1 =>
532
533
val tp = self.baseTypeWithArgs(bc)
533
534
val targs = tp.argInfos
534
535
val tycon = tp.withoutArgs(targs)
535
536
def variancesMatch (param1 : Symbol , param2 : Symbol ) =
536
537
param2.variance == param2.variance || param2.variance == 0
537
- if ((tycon.typeParams corresponds tparams)(variancesMatch)) {
538
+ if (classBounds.exists(tycon.derivesFrom(_)) &&
539
+ tycon.typeParams.corresponds(tparams)(variancesMatch)) {
538
540
val expanded = tycon.EtaExpand
539
541
val lifted = (expanded /: targs) { (partialInst, targ) =>
540
542
val tparam = partialInst.typeParams.head
@@ -549,7 +551,7 @@ class TypeApplications(val self: Type) extends AnyVal {
549
551
false
550
552
}
551
553
if (tparams.isEmpty) false
552
- else if (typeParams.nonEmpty) p(EtaExpand ) || canWiden && tryLift(self.baseClasses)
553
- else canWiden && tryLift(self.baseClasses)
554
+ else if (typeParams.nonEmpty) p(EtaExpand ) || classBounds.nonEmpty && tryLift(self.baseClasses)
555
+ else classBounds.nonEmpty && tryLift(self.baseClasses)
554
556
}
555
557
}
0 commit comments