diff options
author | Martin Odersky <odersky@gmail.com> | 2013-09-05 14:55:57 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-09-05 14:56:09 +0200 |
commit | ae8cc6ff0b3c57877ae60b0b1fd30d1bcefa0518 (patch) | |
tree | 5e0965693224130caf8c0086ad2d7c2de9f02fc5 /src/dotty/tools/dotc/core/TypeComparer.scala | |
parent | 860fd2eb286c48d36655ad99a068a2e61bdb1381 (diff) | |
download | dotty-ae8cc6ff0b3c57877ae60b0b1fd30d1bcefa0518.tar.gz dotty-ae8cc6ff0b3c57877ae60b0b1fd30d1bcefa0518.tar.bz2 dotty-ae8cc6ff0b3c57877ae60b0b1fd30d1bcefa0518.zip |
Changes in typecomparers
1) Fixes for <:<
2) Changes in context handling type comparers that allow one to make a new type comparer that "sticks" in nested contexts.
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeComparer.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index bdfe21561..b3039c730 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -12,7 +12,8 @@ import util.SimpleMap * The constraint set is updated when undetermined type parameters * in the constraint's domain are compared. */ -class TypeComparer(implicit val ctx: Context) extends DotClass { +class TypeComparer(initctx: Context) extends DotClass { + implicit val ctx = initctx val state = ctx.typerState import state.constraint @@ -49,7 +50,7 @@ class TypeComparer(implicit val ctx: Context) extends DotClass { * @pre `param` is associated with type bounds in the current constraint. */ def approximate(param: PolyParam, fromBelow: Boolean): Type = { - val removeParam = new TypeMap { + val avoidParam = new TypeMap { override def apply(tp: Type) = mapOver { tp match { case tp: RefinedType if param occursIn tp.refinedInfo => tp.parent @@ -59,7 +60,7 @@ class TypeComparer(implicit val ctx: Context) extends DotClass { } val bounds = constraint(param).asInstanceOf[TypeBounds] val bound = if (fromBelow) bounds.lo else bounds.hi - val inst = removeParam(bound) + val inst = avoidParam(bound) println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}") constraint = constraint.replace(param, inst) inst @@ -126,12 +127,15 @@ class TypeComparer(implicit val ctx: Context) extends DotClass { secondTry(tp1, tp2) } case tp2: PolyParam => + //println(constraint.show) constraint(tp2) match { case TypeBounds(lo, _) => isSubType(tp1, lo) || addConstraint(tp2, TypeBounds.lower(tp1)) case _ => secondTry(tp1, tp2) } case tp2: TypeVar => - firstTry(tp1, tp2.underlying) + isSubType(tp1, tp2.underlying) + case tp2: ProtoType => + tp2.isMatchedBy(tp1) case tp2: WildcardType => tp2.optBounds match { case TypeBounds(_, hi) => isSubType(tp1, hi) @@ -153,7 +157,7 @@ class TypeComparer(implicit val ctx: Context) extends DotClass { case _ => thirdTry(tp1, tp2) } case tp1: TypeVar => - secondTry(tp1.underlying, tp2) + isSubType(tp1.underlying, tp2) case tp1: WildcardType => tp1.optBounds match { case TypeBounds(lo, _) => isSubType(lo, tp2) @@ -362,10 +366,13 @@ class TypeComparer(implicit val ctx: Context) extends DotClass { if (tp1 == NoType || tp2 == NoType) false else if (tp1 eq tp2) true else isSubType(tp1, tp2) && isSubType(tp2, tp1) + + def copyIn(ctx: Context) = new TypeComparer(ctx) } -class ExplainingTypeComparer(implicit ctx: Context) extends TypeComparer { +class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) { override def isSubType(tp1: Type, tp2: Type) = { - ctx.traceIndented(s"${tp1.show} <:< ${tp2.show}")(super.isSubType(tp1, tp2)) + ctx.traceIndented(s"${tp1} <:< ${tp2}")(super.isSubType(tp1, tp2)) } + override def copyIn(ctx: Context) = new ExplainingTypeComparer(ctx) }
\ No newline at end of file |