diff options
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeApplications.scala | 22 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 46 |
2 files changed, 10 insertions, 58 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 0cf40d818..b1ffe0169 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -169,7 +169,8 @@ object TypeApplications { /** Adapt all arguments to possible higher-kinded type parameters using adaptIfHK */ def adaptArgs(tparams: List[Symbol], args: List[Type])(implicit ctx: Context): List[Type] = - args.zipWithConserve(tparams)((arg, tparam) => arg.adaptIfHK(tparam.infoOrCompleter)) + if (tparams.isEmpty) args + else args.zipWithConserve(tparams)((arg, tparam) => arg.adaptIfHK(tparam.infoOrCompleter)) def argRefs(rt: RefinedType, n: Int)(implicit ctx: Context) = List.range(0, n).map(i => RefinedThis(rt).select(tpnme.hkArg(i))) @@ -234,18 +235,13 @@ class TypeApplications(val self: Type) extends AnyVal { final def paramBounds(implicit ctx: Context): List[TypeBounds] = typeParams.map(self.memberInfo(_).bounds) - def LambdaTrait(implicit ctx: Context) = { - def skipArgs(tp: Type): Type = tp match { - case RefinedType(parent, pname) if pname.isHkArgName => skipArgs(parent) - case _ => tp - } - self.stripTypeVar match { - case RefinedType(parent, tpnme.hkApply) => skipArgs(parent).stripTypeVar match { - case ref @ TypeRef(_, lam) if lam.isLambdaTraitName => ref.symbol - case _ => NoSymbol - } - case _ => NoSymbol - } + /** The Lambda trait underlying a type lambda */ + def LambdaTrait(implicit ctx: Context): Symbol = self.stripTypeVar match { + case RefinedType(parent, tpnme.hkApply) => + val sym = self.classSymbol + if (sym.isLambdaTrait) sym else NoSymbol + case TypeBounds(lo, hi) => hi.LambdaTrait + case _ => NoSymbol } def isEtaExpandable(implicit ctx: Context) = self match { diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index cf7b487bb..747d73ea9 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -21,6 +21,7 @@ import typer.Mode import PickleBuffer._ import scala.reflect.internal.pickling.PickleFormat._ import Decorators._ +import TypeApplications._ import classfile.ClassfileParser import scala.collection.{ mutable, immutable } import scala.collection.mutable.ListBuffer @@ -142,51 +143,6 @@ object Scala2Unpickler { denot.info = ClassInfo( // final info denot.owner.thisType, denot.classSymbol, parentRefs, declsInRightOrder, ost) } - - /** Adapt arguments to type parameters so that variance of type lambda arguments - * agrees with variance of corresponding higherkinded type parameters. Example: - * - * class Companion[+CC[X]] - * Companion[List] - * - * with adaptArgs, this will expand to - * - * Companion[[X] => List[X]] - * - * instead of - * - * Companion[[+X] => List[X]] - * - * even though `List` is covariant. This adaptation is necessary to ignore conflicting - * variances in overriding members that have types of hk-type parameters such as `Companion[GenTraversable]` - * or `Companion[ListBuffer]`. Without the adaptation we would end up with - * - * Companion[[+X] => GenTraversable[X]] - * Companion[[X] => List[X]] - * - * and the second is not a subtype of the first. So if we have overridding memebrs of the two - * types we get an error. - */ - def adaptArgs(tparams: List[Symbol], args: List[Type])(implicit ctx: Context): List[Type] = tparams match { - case tparam :: tparams1 => - val boundLambda = tparam.infoOrCompleter match { - case TypeBounds(_, hi) => hi.LambdaClass(forcing = false) - case _ => NoSymbol - } - def adaptArg(arg: Type): Type = arg match { - case arg: TypeRef if arg.symbol.isLambdaTrait => - assert(arg.symbol.typeParams.length == boundLambda.typeParams.length) - arg.prefix.select(boundLambda) - case arg: RefinedType => - arg.derivedRefinedType(adaptArg(arg.parent), arg.refinedName, arg.refinedInfo) - case _ => - arg - } - val arg = args.head - val adapted = if (boundLambda.exists) adaptArg(arg) else arg - adapted :: adaptArgs(tparams1, args.tail) - case nil => args - } } /** Unpickle symbol table information descending from a class and/or module root |