aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-07-19 17:05:16 +0200
committerMartin Odersky <odersky@gmail.com>2013-07-19 17:05:16 +0200
commit702c4fc89f3ff2abbc7457fd72ab19b5bbdbb782 (patch)
tree9e36761227f5290b742e30072a728950f68e2aa4 /src/dotty/tools/dotc/core
parentea640a32264cb78efbf267d5c2be89e3e99dcccf (diff)
downloaddotty-702c4fc89f3ff2abbc7457fd72ab19b5bbdbb782.tar.gz
dotty-702c4fc89f3ff2abbc7457fd72ab19b5bbdbb782.tar.bz2
dotty-702c4fc89f3ff2abbc7457fd72ab19b5bbdbb782.zip
Handling bounded wildcard types.
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala26
-rw-r--r--src/dotty/tools/dotc/core/Types.scala8
2 files changed, 26 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 479793326..ecd8ec0c4 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -123,30 +123,40 @@ class TypeComparer(implicit val ctx: Context) extends DotClass {
case _ =>
secondTry(tp1, tp2)
}
- case WildcardType | ErrorType =>
- true
- case tp2: TypeVar =>
- firstTry(tp1, tp2.thisInstance)
case tp2: PolyParam =>
constraint(tp2) match {
case TypeBounds(lo, _) => isSubType(tp1, lo) || addConstraint(tp2, TypeBounds.lower(tp1))
case _ => secondTry(tp1, tp2)
}
+ case tp2: TypeVar =>
+ firstTry(tp1, tp2.thisInstance)
+ case tp2: WildcardType =>
+ tp2.optBounds match {
+ case TypeBounds(_, hi) => isSubType(tp1, hi)
+ case NoType => true
+ }
+ case ErrorType =>
+ true
case _ =>
secondTry(tp1, tp2)
}
}
def secondTry(tp1: Type, tp2: Type): Boolean = tp1 match {
- case WildcardType | ErrorType =>
- true
- case tp1: TypeVar =>
- secondTry(tp1.thisInstance, tp2)
case tp1: PolyParam =>
constraint(tp1) match {
case TypeBounds(_, hi) => isSubType(hi, tp2) || addConstraint(tp1, TypeBounds.upper(tp2))
case _ => thirdTry(tp1, tp2)
}
+ case tp1: TypeVar =>
+ secondTry(tp1.thisInstance, tp2)
+ case tp1: WildcardType =>
+ tp1.optBounds match {
+ case TypeBounds(lo, _) => isSubType(lo, tp2)
+ case _ => true
+ }
+ case ErrorType =>
+ true
case _ =>
thirdTry(tp1, tp2)
}
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index e66d86a40..f2b86242d 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1796,6 +1796,8 @@ object Types {
/** Wildcard type, possibly with bounds */
abstract case class WildcardType(optBounds: Type) extends CachedGroundType {
+ def derivedWildcardType(optBounds: Type)(implicit ctx: Context) =
+ if (optBounds eq this.optBounds) this else WildcardType(optBounds.asInstanceOf[TypeBounds])
override def computeHash = doHash(optBounds)
}
@@ -1891,6 +1893,9 @@ object Types {
case tp @ TypeVar(_) =>
apply(tp.thisInstance)
+ case tp @ WildcardType =>
+ tp.derivedWildcardType(mapOver(tp.optBounds))
+
case _ =>
tp
}
@@ -1989,6 +1994,9 @@ object Types {
case tp: TypeVar =>
foldOver(x, tp.thisInstance)
+ case tp: WildcardType =>
+ foldOver(x, tp.optBounds)
+
case _ => x
}
}