From 31af865656ecc352c39ce919981e9b50d42a3237 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 29 Jun 2016 19:48:40 +0200 Subject: Fix condition for lambda abstracting in Namer The previous condition could make a (derived) type a * type for a little while even though it had type parameters. This loophole caused collection/generic/MapFactory.scala and with it compile-stdlib to fail. Refinement for knownHK for PolyParams pos test t2082.scala shows that knownHK can be constructed before the binder PolyType of a PolyParam is initialized. --- src/dotty/tools/dotc/core/TypeApplications.scala | 10 +++------- src/dotty/tools/dotc/core/Types.scala | 6 +++++- src/dotty/tools/dotc/typer/Namer.scala | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index fc8876d09..c0728a8fb 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -494,7 +494,9 @@ class TypeApplications(val self: Type) extends AnyVal { case self: SingletonType => -1 case self: TypeVar => self.origin.knownHK case self: WildcardType => self.optBounds.knownHK + case self: PolyParam => self.underlying.knownHK case self: TypeProxy => self.underlying.knownHK + case NoType => 0 case _ => -1 } @@ -666,13 +668,7 @@ class TypeApplications(val self: Type) extends AnyVal { instTop(tp.ref) case tp => inst.tyconIsHK = tp.isHK - val res = inst(tp) - tp match { - case tp: WildcardType => - println(s"inst $tp --> $res") - case _ => - } - res + inst(tp) } def isLazy(tp: Type): Boolean = tp.strictDealias match { diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 986a9c292..d3e97b492 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2765,7 +2765,11 @@ object Types { def paramName = binder.paramNames(paramNum) - override def underlying(implicit ctx: Context): Type = binder.paramBounds(paramNum) + override def underlying(implicit ctx: Context): Type = { + val bounds = binder.paramBounds + if (bounds == null) NoType // this can happen if the PolyType is not initialized yet + else bounds(paramNum) + } // no customized hashCode/equals needed because cycle is broken in PolyType override def toString = s"PolyParam($paramName)" diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 7982f288d..bc8f8e281 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -935,7 +935,7 @@ class Namer { typer: Typer => //val toParameterize = tparamSyms.nonEmpty && !isDerived //val needsLambda = sym.allOverriddenSymbols.exists(_ is HigherKinded) && !isDerived def abstracted(tp: Type): Type = - if (tparamSyms.nonEmpty && !isDerived) tp.LambdaAbstract(tparamSyms) + if (tparamSyms.nonEmpty && !tp.isHK) tp.LambdaAbstract(tparamSyms) //else if (toParameterize) tp.parameterizeWith(tparamSyms) else tp -- cgit v1.2.3