diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-24 19:07:05 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-26 18:52:33 +0100 |
commit | d6b5f23bc389e1d7af0b69305708f59941dc34d1 (patch) | |
tree | 306c475e1156558515ed280929049e7f005639dc /src/dotty/tools/dotc/core/Types.scala | |
parent | f01071323516e699a169d89e5ac848215b6488c2 (diff) | |
download | dotty-d6b5f23bc389e1d7af0b69305708f59941dc34d1.tar.gz dotty-d6b5f23bc389e1d7af0b69305708f59941dc34d1.tar.bz2 dotty-d6b5f23bc389e1d7af0b69305708f59941dc34d1.zip |
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.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 15 |
1 files changed, 9 insertions, 6 deletions
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 ------------------------------------------------------------ |