From d6b5f23bc389e1d7af0b69305708f59941dc34d1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 24 Jan 2014 19:07:05 +0100 Subject: Fixes to constraint handling. In particular, need to unify polyparams before replacing one with the other, if the result wiould lead to a cyclic constraint. Also: Avoid setting `inst` field of a type variable if a subtype operation is in progress, because the constraint might be retracted, and the instantiation should be retracted with it. Third, tighter checks of cyclic constraint, and deep subtype recursions can now be demanded to cause an abort. --- src/dotty/tools/dotc/core/Types.scala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/dotty/tools/dotc/core/Types.scala') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index bfe4ae5be..6c9bc4f10 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1696,12 +1696,12 @@ object Types { * - fromBelow and param <:< bound * - !fromBelow and param >:> bound */ - def occursIn(bound: Type, fromBelow: Boolean): Boolean = bound match { + def occursIn(bound: Type, fromBelow: Boolean)(implicit ctx: Context): Boolean = bound.stripTypeVar match { case bound: PolyParam => bound == this case bound: AndOrType => def occ1 = occursIn(bound.tp1, fromBelow) def occ2 = occursIn(bound.tp2, fromBelow) - if (fromBelow == bound.isAnd) occ1 & occ2 else occ1 || occ2 + if (fromBelow == bound.isAnd) occ1 && occ2 else occ1 || occ2 case _ => false } @@ -1761,10 +1761,11 @@ object Types { /** Instantiate variable with given type */ private def instantiateWith(tp: Type)(implicit ctx: Context): Type = { - assert(tp ne this) + assert(tp ne this, s"self instantiation of ${tp.show}, constraint = ${ctx.typerState.constraint.show}") typr.println(s"instantiating ${this.show} with ${tp.show}") assert(ctx.typerState.constraint contains this) // !!! DEBUG - if (ctx.typerState eq owningState) inst = tp + if ((ctx.typerState eq owningState) && !ctx.typeComparer.subtypeCheckInProgress) + inst = tp ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp) tp } @@ -1807,8 +1808,10 @@ object Types { override def hashCode: Int = System.identityHashCode(this) override def equals(that: Any) = this eq that.asInstanceOf[AnyRef] - override def toString = - if (inst.exists) inst.toString else s"TypeVar($origin)" + override def toString = { + def instStr = if (inst.exists) s" -> $inst" else "" + s"TypeVar($origin$instStr)" + } } // ------ ClassInfo, Type Bounds ------------------------------------------------------------ -- cgit v1.2.3