Skip to content

Commit 5c3bff1

Browse files
committed
Allow for F-bounded bounds in TypeLambda
1 parent 4a7b3d3 commit 5c3bff1

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@ object TypeApplications {
5454
*/
5555
object TypeLambda {
5656
def apply(variances: List[Int],
57-
argBoundss: List[TypeBounds],
57+
argBoundsFns: List[RefinedType => TypeBounds],
5858
bodyFn: RefinedType => Type)(implicit ctx: Context): Type = {
59-
def argRefinements(parent: Type, i: Int, bs: List[TypeBounds]): Type = bs match {
59+
def argRefinements(parent: Type, i: Int, bs: List[RefinedType => TypeBounds]): Type = bs match {
6060
case b :: bs1 =>
6161
argRefinements(RefinedType(parent, tpnme.hkArg(i), b), i + 1, bs1)
6262
case nil =>
6363
parent
6464
}
6565
assert(variances.nonEmpty)
66-
assert(argBoundss.length == variances.length)
66+
assert(argBoundsFns.length == variances.length)
6767
RefinedType(
68-
argRefinements(defn.LambdaTrait(variances).typeRef, 0, argBoundss),
68+
argRefinements(defn.LambdaTrait(variances).typeRef, 0, argBoundsFns),
6969
tpnme.hkApply, bodyFn(_).bounds.withVariance(1))
7070
}
7171

@@ -94,7 +94,9 @@ object TypeApplications {
9494
assert(tycon.isEtaExpandable)
9595
val tparams = tycon.typeParams
9696
val variances = tycon.typeParams.map(_.variance)
97-
TypeLambda(tparams.map(_.variance), tycon.paramBounds,
97+
TypeLambda(
98+
tparams.map(_.variance),
99+
tycon.paramBounds.map(internalize(_, tycon.typeParams)),
98100
rt => tycon.appliedTo(argRefs(rt, tparams.length)))
99101
}
100102

@@ -162,7 +164,11 @@ object TypeApplications {
162164
}
163165
}
164166

165-
/** Adapt all arguments to possible higher-kinded type parameters using adaptIfHK
167+
private def internalize[T <: Type](tp: T, tparams: List[Symbol])(implicit ctx: Context) =
168+
(rt: RefinedType) =>
169+
new ctx.SafeSubstMap(tparams, argRefs(rt, tparams.length)).apply(tp).asInstanceOf[T]
170+
171+
/** Adapt all arguments to possible higher-kinded type parameters using adaptIfHK
166172
*/
167173
def adaptArgs(tparams: List[Symbol], args: List[Type])(implicit ctx: Context): List[Type] =
168174
if (tparams.isEmpty) args
@@ -257,8 +263,10 @@ class TypeApplications(val self: Type) extends AnyVal {
257263
*/
258264
def LambdaAbstract(tparams: List[Symbol])(implicit ctx: Context): Type = {
259265
def expand(tp: Type) = {
260-
TypeLambda(tparams.map(_.variance), tparams.map(_.info.bounds),
261-
rt => new ctx.SafeSubstMap(tparams, argRefs(rt, tparams.length)).apply(tp))
266+
TypeLambda(
267+
tparams.map(_.variance),
268+
tparams.map(tparam => internalize(tparam.info.bounds, tparams)),
269+
internalize(tp, tparams))
262270
}
263271
self match {
264272
case self: TypeAlias =>

0 commit comments

Comments
 (0)