From 50d265299ab99ace68e3813794559de2bbcdc91c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 6 Dec 2015 09:24:43 +0100 Subject: 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. --- src/dotty/tools/dotc/core/TypeApplications.scala | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index b86c58030..db7550402 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -92,12 +92,7 @@ object TypeApplications { object EtaExpansion { def apply(tycon: TypeRef)(implicit ctx: Context) = { assert(tycon.isEtaExpandable) - val tparams = tycon.typeParams - val variances = tycon.typeParams.map(_.variance) - TypeLambda( - tparams.map(_.variance), - tycon.paramBounds.map(internalize(_, tycon.typeParams)), - rt => tycon.appliedTo(argRefs(rt, tparams.length))) + tycon.EtaExpand(tycon.typeParams) } def unapply(tp: Type)(implicit ctx: Context): Option[TypeRef] = { @@ -164,10 +159,6 @@ object TypeApplications { } } - private def internalize[T <: Type](tp: T, tparams: List[Symbol])(implicit ctx: Context) = - (rt: RefinedType) => - new ctx.SafeSubstMap(tparams, argRefs(rt, tparams.length)).apply(tp).asInstanceOf[T] - /** Adapt all arguments to possible higher-kinded type parameters using adaptIfHK */ def adaptArgs(tparams: List[Symbol], args: List[Type])(implicit ctx: Context): List[Type] = @@ -235,9 +226,6 @@ class TypeApplications(val self: Type) extends AnyVal { final def hkTypeParams(implicit ctx: Context): List[TypeSymbol] = self.LambdaTrait.typeParams - final def paramBounds(implicit ctx: Context): List[TypeBounds] = - typeParams.map(self.memberInfo(_).bounds) - /** The Lambda trait underlying a type lambda */ def LambdaTrait(implicit ctx: Context): Symbol = self.stripTypeVar match { case RefinedType(parent, tpnme.hkApply) => @@ -262,11 +250,15 @@ class TypeApplications(val self: Type) extends AnyVal { * type T[X] >: L <: U becomes type T >: L <: ([X] -> _ <: U) */ def LambdaAbstract(tparams: List[Symbol])(implicit ctx: Context): Type = { + def internalize[T <: Type](tp: T) = + (rt: RefinedType) => + new ctx.SafeSubstMap(tparams, argRefs(rt, tparams.length)) + .apply(tp).asInstanceOf[T] def expand(tp: Type) = { TypeLambda( tparams.map(_.variance), - tparams.map(tparam => internalize(tparam.info.bounds, tparams)), - internalize(tp, tparams)) + tparams.map(tparam => internalize(self.memberInfo(tparam).bounds)), + internalize(tp)) } self match { case self: TypeAlias => -- cgit v1.2.3