aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-13 14:39:13 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-13 14:39:26 +0100
commit620359dc261c12456519c142e3a6e9842f750989 (patch)
tree56c85f5b2e0b1da1eeb720ed7d4a9b5ba04e67a0
parent12983c39486b3759028502125944f09d62267e83 (diff)
downloaddotty-620359dc261c12456519c142e3a6e9842f750989.tar.gz
dotty-620359dc261c12456519c142e3a6e9842f750989.tar.bz2
dotty-620359dc261c12456519c142e3a6e9842f750989.zip
When instantiating a type var, need to map back from polyparams to typevars.
-rw-r--r--src/dotty/tools/dotc/core/Constraint.scala9
-rw-r--r--src/dotty/tools/dotc/core/Types.scala7
2 files changed, 14 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Constraint.scala b/src/dotty/tools/dotc/core/Constraint.scala
index 8704a35d8..b47cc921c 100644
--- a/src/dotty/tools/dotc/core/Constraint.scala
+++ b/src/dotty/tools/dotc/core/Constraint.scala
@@ -59,6 +59,15 @@ class Constraint(val myMap: SimpleMap[PolyType, Array[Type]]) extends AnyVal wit
*/
def bounds(param: PolyParam): TypeBounds = at(param).asInstanceOf[TypeBounds]
+ /** The type variable corresponding to parameter `param`, or
+ * NoType, if `param` is not in constrained or is not paired with a type variable.
+ */
+ def typeVarOfParam(param: PolyParam): Type = {
+ val entries = myMap(param.binder)
+ if (entries == null) NoType
+ else typeVar(entries, param.paramNum)
+ }
+
/** A new constraint which is derived from this constraint by adding or replacing
* the entries corresponding to `pt` with `entries`.
*/
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 4b3dfe2b7..85e89fa62 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -857,7 +857,8 @@ object Types {
* variable instances and reduces typerefs over refined types. It also
* re-evaluatesall occurrences of And/OrType with &/| because
* what was a union or intersection of type variables might be a simpler type
- * after the type variables are instantiated.
+ * after the type variables are instantiated. Finally, it
+ * maps poly params in the current constraint set back to their type vars.
*/
def simplified(implicit ctx: Context) = {
class Simplify extends TypeMap {
@@ -866,6 +867,8 @@ object Types {
mapOver(l) & mapOver(r)
case OrType(l, r) =>
mapOver(l) | mapOver(r)
+ case tp: PolyParam =>
+ ctx.typerState.constraint.typeVarOfParam(tp) orElse tp
case _ =>
mapOver(tp)
}
@@ -1736,7 +1739,7 @@ object Types {
def isInstantiated(implicit ctx: Context) = instanceOpt.exists
/** Instantiate variable with given type */
- def instantiateWith(tp: Type)(implicit ctx: Context): Type = {
+ private def instantiateWith(tp: Type)(implicit ctx: Context): Type = {
assert(tp ne this)
typr.println(s"instantiating ${this.show} with ${tp.show}")
assert(ctx.typerState.constraint contains this) // !!! DEBUG