@@ -2393,6 +2393,7 @@ object Types {
2393
2393
2394
2394
abstract class HKLambda extends CachedProxyType with LambdaType {
2395
2395
final override def computeHash = doHash(paramNames, resType, paramInfos)
2396
+ final override def underlying (implicit ctx : Context ) = resType
2396
2397
}
2397
2398
2398
2399
abstract class StarLambda extends CachedGroundType with LambdaType with TermType {
@@ -2653,6 +2654,30 @@ object Types {
2653
2654
}
2654
2655
}
2655
2656
2657
+ class HKTypeLambda (val paramNames : List [TypeName ])(
2658
+ paramInfosExp : HKTypeLambda => List [TypeBounds ], resultTypeExp : HKTypeLambda => Type )
2659
+ extends HKLambda with TypeLambda {
2660
+ type This = HKTypeLambda
2661
+ def companion = HKTypeLambda
2662
+
2663
+ val paramInfos : List [TypeBounds ] = paramInfosExp(this )
2664
+ val resType : Type = resultTypeExp(this )
2665
+
2666
+ assert(resType.isInstanceOf [TermType ], this )
2667
+ assert(paramNames.nonEmpty)
2668
+
2669
+ /** The type `[tparams := paramRefs] tp`, where `tparams` can be
2670
+ * either a list of type parameter symbols or a list of lambda parameters
2671
+ */
2672
+ def lifted (tparams : List [ParamInfo ], tp : Type )(implicit ctx : Context ): Type =
2673
+ tparams match {
2674
+ case LambdaParam (poly, _) :: _ => tp.subst(poly, this )
2675
+ case tparams : List [Symbol @ unchecked] => tp.subst(tparams, paramRefs)
2676
+ }
2677
+
2678
+ protected def prefixString = " HKTypeLambda"
2679
+ }
2680
+
2656
2681
/** A type lambda of the form `[X_0 B_0, ..., X_n B_n] => T`
2657
2682
* This is used both as a type of a polymorphic method and as a type of
2658
2683
* a higher-kinded type parameter. Variances are encoded in parameter
@@ -2673,17 +2698,12 @@ object Types {
2673
2698
type This = PolyType
2674
2699
def companion = PolyType
2675
2700
2676
- /** The bounds of the type parameters */
2677
2701
val paramInfos : List [TypeBounds ] = paramInfosExp(this )
2678
-
2679
- /** The result type of a PolyType / body of a type lambda */
2680
2702
val resType : Type = resultTypeExp(this )
2681
2703
2682
2704
assert(resType.isInstanceOf [TermType ], this )
2683
2705
assert(paramNames.nonEmpty)
2684
2706
2685
- override def underlying (implicit ctx : Context ) = resType
2686
-
2687
2707
/** Merge nested polytypes into one polytype. nested polytypes are normally not supported
2688
2708
* but can arise as temporary data structures.
2689
2709
*/
@@ -2714,6 +2734,21 @@ object Types {
2714
2734
protected def prefixString = " PolyType"
2715
2735
}
2716
2736
2737
+ object HKTypeLambda extends TypeLambdaCompanion [HKTypeLambda ] {
2738
+ def apply (paramNames : List [TypeName ])(
2739
+ paramInfosExp : HKTypeLambda => List [TypeBounds ],
2740
+ resultTypeExp : HKTypeLambda => Type )(implicit ctx : Context ): HKTypeLambda = {
2741
+ unique(new HKTypeLambda (paramNames)(paramInfosExp, resultTypeExp))
2742
+ }
2743
+
2744
+ def unapply (tl : HKTypeLambda ): Some [(List [LambdaParam ], Type )] =
2745
+ Some ((tl.typeParams, tl.resType))
2746
+
2747
+ def any (n : Int )(implicit ctx : Context ) =
2748
+ apply(syntheticParamNames(n))(
2749
+ pt => List .fill(n)(TypeBounds .empty), pt => defn.AnyType )
2750
+ }
2751
+
2717
2752
object PolyType extends TypeLambdaCompanion [PolyType ] {
2718
2753
def apply (paramNames : List [TypeName ])(
2719
2754
paramInfosExp : PolyType => List [TypeBounds ],
0 commit comments