Skip to content

Commit d5619ae

Browse files
committed
Make Term Lambda parameters distribute into bounds
Analogous to type lambda parameters
1 parent 34ac63c commit d5619ae

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

compiler/src/dotty/tools/dotc/config/Config.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ object Config {
9797
*/
9898
final val checkHKApplications = false
9999

100-
/** If this flag is set, method types are checked for valid parameter references
100+
/** If this flag is set, term lambda types are checked for valid parameter references
101101
*/
102-
final val checkMethodTypes = false
102+
final val checkTermLambdas = false
103103

104104
/** If this flag is set, it is checked that TypeRefs don't refer directly
105105
* to themselves.

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,30 +3131,15 @@ object Types {
31313131
protected def prefixString = "PolyType"
31323132
}
31333133

3134-
object HKTypeLambda extends TypeLambdaCompanion[HKTypeLambda] {
3135-
def apply(paramNames: List[TypeName])(
3136-
paramInfosExp: HKTypeLambda => List[TypeBounds],
3137-
resultTypeExp: HKTypeLambda => Type)(implicit ctx: Context): HKTypeLambda = {
3138-
unique(new HKTypeLambda(paramNames)(paramInfosExp, resultTypeExp))
3139-
}
3140-
3141-
def unapply(tl: HKTypeLambda): Some[(List[LambdaParam], Type)] =
3142-
Some((tl.typeParams, tl.resType))
3143-
3144-
def any(n: Int)(implicit ctx: Context) =
3145-
apply(syntheticParamNames(n))(
3146-
pt => List.fill(n)(TypeBounds.empty), pt => defn.AnyType)
3147-
3148-
override def paramName(param: ParamInfo.Of[TypeName])(implicit ctx: Context): TypeName =
3149-
param.paramName.withVariance(param.paramVariance)
3134+
trait HKCompanion[N <: Name, PInfo <: Type, LT <: LambdaType] extends LambdaTypeCompanion[N, PInfo, LT] {
31503135

31513136
/** Distributes Lambda inside type bounds. Examples:
31523137
*
31533138
* type T[X] = U becomes type T = [X] -> U
31543139
* type T[X] <: U becomes type T >: Nothign <: ([X] -> U)
31553140
* type T[X] >: L <: U becomes type T >: ([X] -> L) <: ([X] -> U)
31563141
*/
3157-
override def fromParams[PI <: ParamInfo.Of[TypeName]](params: List[PI], resultType: Type)(implicit ctx: Context): Type = {
3142+
override def fromParams[PI <: ParamInfo.Of[N]](params: List[PI], resultType: Type)(implicit ctx: Context): Type = {
31583143
def expand(tp: Type) = super.fromParams(params, tp)
31593144
resultType match {
31603145
case rt: TypeAlias =>
@@ -3168,7 +3153,25 @@ object Types {
31683153
}
31693154
}
31703155

3171-
object HKTermLambda extends TermLambdaCompanion[HKTermLambda] {
3156+
object HKTypeLambda extends TypeLambdaCompanion[HKTypeLambda] with HKCompanion[TypeName, TypeBounds, HKTypeLambda] {
3157+
def apply(paramNames: List[TypeName])(
3158+
paramInfosExp: HKTypeLambda => List[TypeBounds],
3159+
resultTypeExp: HKTypeLambda => Type)(implicit ctx: Context): HKTypeLambda = {
3160+
unique(new HKTypeLambda(paramNames)(paramInfosExp, resultTypeExp))
3161+
}
3162+
3163+
def unapply(tl: HKTypeLambda): Some[(List[LambdaParam], Type)] =
3164+
Some((tl.typeParams, tl.resType))
3165+
3166+
def any(n: Int)(implicit ctx: Context) =
3167+
apply(syntheticParamNames(n))(
3168+
pt => List.fill(n)(TypeBounds.empty), pt => defn.AnyType)
3169+
3170+
override def paramName(param: ParamInfo.Of[TypeName])(implicit ctx: Context): TypeName =
3171+
param.paramName.withVariance(param.paramVariance)
3172+
}
3173+
3174+
object HKTermLambda extends TermLambdaCompanion[HKTermLambda] with HKCompanion[TermName, Type, HKTermLambda] {
31723175
def apply(paramNames: List[TermName])(
31733176
paramInfosExp: HKTermLambda => List[Type],
31743177
resultTypeExp: HKTermLambda => Type)(implicit ctx: Context): HKTermLambda = {

0 commit comments

Comments
 (0)