Skip to content

Commit 9fbffdc

Browse files
committed
Be DRY betweeen EtaExpand and LambdaAbstract
All Lambda abstractions, not just eta expansions, should use actual parameter bounds, not the one retrieved from the parameter symbols.
1 parent 5c3bff1 commit 9fbffdc

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ object TypeApplications {
9292
object EtaExpansion {
9393
def apply(tycon: TypeRef)(implicit ctx: Context) = {
9494
assert(tycon.isEtaExpandable)
95-
val tparams = tycon.typeParams
96-
val variances = tycon.typeParams.map(_.variance)
97-
TypeLambda(
98-
tparams.map(_.variance),
99-
tycon.paramBounds.map(internalize(_, tycon.typeParams)),
100-
rt => tycon.appliedTo(argRefs(rt, tparams.length)))
95+
tycon.EtaExpand(tycon.typeParams)
10196
}
10297

10398
def unapply(tp: Type)(implicit ctx: Context): Option[TypeRef] = {
@@ -164,10 +159,6 @@ object TypeApplications {
164159
}
165160
}
166161

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-
171162
/** Adapt all arguments to possible higher-kinded type parameters using adaptIfHK
172163
*/
173164
def adaptArgs(tparams: List[Symbol], args: List[Type])(implicit ctx: Context): List[Type] =
@@ -235,9 +226,6 @@ class TypeApplications(val self: Type) extends AnyVal {
235226
final def hkTypeParams(implicit ctx: Context): List[TypeSymbol] =
236227
self.LambdaTrait.typeParams
237228

238-
final def paramBounds(implicit ctx: Context): List[TypeBounds] =
239-
typeParams.map(self.memberInfo(_).bounds)
240-
241229
/** The Lambda trait underlying a type lambda */
242230
def LambdaTrait(implicit ctx: Context): Symbol = self.stripTypeVar match {
243231
case RefinedType(parent, tpnme.hkApply) =>
@@ -262,11 +250,15 @@ class TypeApplications(val self: Type) extends AnyVal {
262250
* type T[X] >: L <: U becomes type T >: L <: ([X] -> _ <: U)
263251
*/
264252
def LambdaAbstract(tparams: List[Symbol])(implicit ctx: Context): Type = {
253+
def internalize[T <: Type](tp: T) =
254+
(rt: RefinedType) =>
255+
new ctx.SafeSubstMap(tparams, argRefs(rt, tparams.length))
256+
.apply(tp).asInstanceOf[T]
265257
def expand(tp: Type) = {
266258
TypeLambda(
267259
tparams.map(_.variance),
268-
tparams.map(tparam => internalize(tparam.info.bounds, tparams)),
269-
internalize(tp, tparams))
260+
tparams.map(tparam => internalize(self.memberInfo(tparam).bounds)),
261+
internalize(tp))
270262
}
271263
self match {
272264
case self: TypeAlias =>

0 commit comments

Comments
 (0)