Skip to content

Commit c59183f

Browse files
committed
Add LambdaType#instantiateParamInfos
This generalizes TypeLambda#instantiateBounds to all LambdaTypes.
1 parent df48ce1 commit c59183f

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
193193
def polyDefDef(sym: TermSymbol, rhsFn: List[Type] => List[List[Tree]] => Tree)(implicit ctx: Context): DefDef = {
194194
val (tparams, mtp) = sym.info match {
195195
case tp: PolyType =>
196-
val tparams = ctx.newTypeParams(sym, tp.paramNames, EmptyFlags, tp.instantiateBounds)
196+
val tparams = ctx.newTypeParams(sym, tp.paramNames, EmptyFlags, tp.instantiateParamInfos(_))
197197
(tparams, tp.instantiate(tparams map (_.typeRef)))
198198
case tp => (Nil, tp)
199199
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,12 @@ object Types {
26642664
myParamRefs
26652665
}
26662666

2667+
/** Like `paramInfos` but substitute parameter references with the given arguments */
2668+
final def instantiateParamInfos(argTypes: => List[Type])(implicit ctx: Context): List[Type] =
2669+
if (isParamDependent) paramInfos.mapConserve(_.substParams(this, argTypes))
2670+
else paramInfos
2671+
2672+
/** Like `resultType` but substitute parameter references with the given arguments */
26672673
final def instantiate(argTypes: => List[Type])(implicit ctx: Context): Type =
26682674
if (isResultDependent) resultType.substParams(this, argTypes)
26692675
else resultType
@@ -2998,10 +3004,6 @@ object Types {
29983004
lazy val typeParams: List[LambdaParam] =
29993005
paramNames.indices.toList.map(new LambdaParam(this, _))
30003006

3001-
/** Instantiate parameter bounds by substituting parameters with given arguments */
3002-
final def instantiateBounds(argTypes: List[Type])(implicit ctx: Context): List[Type] =
3003-
paramInfos.mapConserve(_.substParams(this, argTypes))
3004-
30053007
def derivedLambdaAbstraction(paramNames: List[TypeName], paramInfos: List[TypeBounds], resType: Type)(implicit ctx: Context): Type =
30063008
resType match {
30073009
case resType @ TypeAlias(alias) =>

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
11201120
val tp1Params = tp1.newLikeThis(tp1.paramNames, tp1.paramInfos, defn.AnyType)
11211121
fullyDefinedType(tp1Params, "type parameters of alternative", alt1.symbol.pos)
11221122

1123-
val tparams = ctx.newTypeParams(alt1.symbol, tp1.paramNames, EmptyFlags, tp1.instantiateBounds)
1123+
val tparams = ctx.newTypeParams(alt1.symbol, tp1.paramNames, EmptyFlags, tp1.instantiateParamInfos(_))
11241124
isAsSpecific(alt1, tp1.instantiate(tparams.map(_.typeRef)), alt2, tp2)
11251125
}
11261126
case _ => // (3)

0 commit comments

Comments
 (0)