aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-14 16:53:41 +0100
committerMartin Odersky <odersky@gmail.com>2017-02-14 16:53:41 +0100
commitb89738672662863168453a1bd6c6c47a6ff07f11 (patch)
tree3799954fb6ac7aa581786031834f440172a4e166
parent17469b82ca7afc5376bc3906bb5b64d10f38a100 (diff)
downloaddotty-b89738672662863168453a1bd6c6c47a6ff07f11.tar.gz
dotty-b89738672662863168453a1bd6c6c47a6ff07f11.tar.bz2
dotty-b89738672662863168453a1bd6c6c47a6ff07f11.zip
Avoid automatism for passing variances to PolyTypes
We used to "fill-in" with zeroes if variances were missing. I now think that;'s too error-prone. Better define all variances explicitly.
-rw-r--r--compiler/src/dotty/tools/dotc/core/Definitions.scala3
-rw-r--r--compiler/src/dotty/tools/dotc/core/Types.scala7
-rw-r--r--compiler/src/dotty/tools/dotc/transform/FullParameterization.scala5
3 files changed, 8 insertions, 7 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala
index 2797bb8a6..c61e92f3a 100644
--- a/compiler/src/dotty/tools/dotc/core/Definitions.scala
+++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala
@@ -9,6 +9,7 @@ import scala.annotation.{ switch, meta }
import scala.collection.{ mutable, immutable }
import PartialFunction._
import collection.mutable
+import util.common.alwaysZero
import scala.reflect.api.{ Universe => ApiUniverse }
object Definitions {
@@ -152,7 +153,7 @@ class Definitions {
resultTypeFn: PolyType => Type, flags: FlagSet = EmptyFlags) = {
val tparamNames = tpnme.syntheticTypeParamNames(typeParamCount)
val tparamBounds = tparamNames map (_ => TypeBounds.empty)
- val ptype = PolyType(tparamNames)(_ => tparamBounds, resultTypeFn)
+ val ptype = PolyType(tparamNames, tparamNames.map(alwaysZero))(_ => tparamBounds, resultTypeFn)
enterMethod(cls, name, ptype, flags)
}
diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala
index ae9122853..1174e863e 100644
--- a/compiler/src/dotty/tools/dotc/core/Types.scala
+++ b/compiler/src/dotty/tools/dotc/core/Types.scala
@@ -2603,7 +2603,7 @@ object Types {
case t => mapOver(t)
}
}
- PolyType(paramNames ++ that.paramNames)(
+ PolyType(paramNames ++ that.paramNames, variances ++ that.variances)(
x => this.paramBounds.mapConserve(_.subst(this, x).bounds) ++
that.paramBounds.mapConserve(shift(_).subst(that, x).bounds),
x => shift(that.resultType).subst(that, x).subst(this, x))
@@ -2634,11 +2634,10 @@ object Types {
}
object PolyType {
- def apply(paramNames: List[TypeName], variances: List[Int] = Nil)(
+ def apply(paramNames: List[TypeName], variances: List[Int])(
paramBoundsExp: PolyType => List[TypeBounds],
resultTypeExp: PolyType => Type)(implicit ctx: Context): PolyType = {
- val vs = if (variances.isEmpty) paramNames.map(alwaysZero) else variances
- unique(new PolyType(paramNames, vs)(paramBoundsExp, resultTypeExp))
+ unique(new PolyType(paramNames, variances)(paramBoundsExp, resultTypeExp))
}
def unapply(tl: PolyType): Some[(List[LambdaParam], Type)] =
diff --git a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala
index 6c69c735b..9e43fc999 100644
--- a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala
+++ b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala
@@ -101,6 +101,7 @@ trait FullParameterization {
}
val ctparams = if (abstractOverClass) clazz.typeParams else Nil
val ctnames = ctparams.map(_.name.unexpandedName)
+ val ctvariances = ctparams.map(_.variance)
/** The method result type */
def resultType(mapClassParams: Type => Type) = {
@@ -122,14 +123,14 @@ trait FullParameterization {
info match {
case info: PolyType =>
- PolyType(info.paramNames ++ ctnames)(
+ PolyType(info.paramNames ++ ctnames, info.variances ++ ctvariances)(
pt =>
(info.paramBounds.map(mapClassParams(_, pt).bounds) ++
mappedClassBounds(pt)).mapConserve(_.subst(info, pt).bounds),
pt => resultType(mapClassParams(_, pt)).subst(info, pt))
case _ =>
if (ctparams.isEmpty) resultType(identity)
- else PolyType(ctnames)(mappedClassBounds, pt => resultType(mapClassParams(_, pt)))
+ else PolyType(ctnames, ctvariances)(mappedClassBounds, pt => resultType(mapClassParams(_, pt)))
}
}