From 2a8abfa8da9742e0a8b5460c6032d7ef610e44ab Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 23 Sep 2013 12:28:57 +0200 Subject: Avoided a cyclic reference error when dealing with hk types. --- src/dotty/tools/dotc/core/Types.scala | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 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 b97c569ef..33eeff5c8 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1423,6 +1423,7 @@ object Types { if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) this else if (refinedName.isHkParamName && + parent.typeSymbol.isCompleted && // to avoid cyclic reference errors refinedName.hkParamIndex < typeParams.length && originalName != refinedName) derivedRefinedType(parent, originalName, refinedInfo) @@ -1467,6 +1468,10 @@ object Types { if ((tp1 eq this.tp1) && (tp2 eq this.tp2)) this else AndType(tp1, tp2) + def derived_& (tp1: Type, tp2: Type)(implicit ctx: Context) = + if ((tp1 eq this.tp1) && (tp2 eq this.tp2)) this + else tp1 & tp2 + override def computeHash = doHash(tp1, tp2) } @@ -1482,6 +1487,10 @@ object Types { if ((tp1 eq this.tp1) && (tp2 eq this.tp2)) this else OrType(tp1, tp2) + def derived_| (tp1: Type, tp2: Type)(implicit ctx: Context) = + if ((tp1 eq this.tp1) && (tp2 eq this.tp2)) this + else tp1 | tp2 + override def computeHash = doHash(tp1, tp2) } @@ -1879,6 +1888,8 @@ object Types { else ClassInfo(prefix, cls, classParents, decls, selfInfo) override def computeHash = doHash(cls, prefix) + + override def toString = s"ClassInfo($prefix, $cls)" } final class CachedClassInfo(prefix: Type, cls: ClassSymbol, classParents: List[TypeRef], decls: Scope, selfInfo: DotClass) @@ -2123,6 +2134,12 @@ object Types { val inst = tp.instanceOpt if (inst.exists) apply(inst) else tp + case tp: AndType => + tp.derivedAndType(this(tp.tp1), this(tp.tp2)) + + case tp: OrType => + tp.derivedOrType(this(tp.tp1), this(tp.tp2)) + case tp @ WildcardType => tp.derivedWildcardType(mapOver(tp.optBounds)) @@ -2302,15 +2319,6 @@ object Types { class CyclicReference(val denot: SymDenotation) extends FatalTypeError(s"cyclic reference involving $denot") - class ClassMergeError(cinfo: ClassInfo, tp2: Type)(implicit ctx: Context) - extends FatalTypeError(s"cannot merge ${showTypeType(cinfo)} with ${showTypeType(tp2)} as members of ${cinfo.prefix.show}") - - private def showTypeType(tp: Type)(implicit ctx: Context) = tp match { - case ClassInfo(_, cls, _, _, _) => cls.showLocated - case bounds: TypeBounds => "type bounds" + bounds.show - case _ => tp.show - } - // ----- Debug --------------------------------------------------------- var debugTrace = false -- cgit v1.2.3