aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/ConstraintHandling.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-01-19 12:17:24 +0100
committerMartin Odersky <odersky@gmail.com>2015-01-19 12:30:45 +0100
commit68d58a651ee5a7853e58d40fa1decadd10df110c (patch)
tree2c0ea145a984731af5f4b84d0cfa7418a3b3d414 /src/dotty/tools/dotc/core/ConstraintHandling.scala
parent01f1a26bbfa6763eba960ac71f9d71cebed478df (diff)
downloaddotty-68d58a651ee5a7853e58d40fa1decadd10df110c.tar.gz
dotty-68d58a651ee5a7853e58d40fa1decadd10df110c.tar.bz2
dotty-68d58a651ee5a7853e58d40fa1decadd10df110c.zip
Move PolyParam test later in isSubType and simplify addConstraint
Motivation: Would like to profit from normalizations done before, so that we do not have to redo them in addConstraint. Also: eliminate solvedConstraint; it is no longer needed and was always false.
Diffstat (limited to 'src/dotty/tools/dotc/core/ConstraintHandling.scala')
-rw-r--r--src/dotty/tools/dotc/core/ConstraintHandling.scala24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/core/ConstraintHandling.scala b/src/dotty/tools/dotc/core/ConstraintHandling.scala
index ff7ffdfb1..e79dc28b9 100644
--- a/src/dotty/tools/dotc/core/ConstraintHandling.scala
+++ b/src/dotty/tools/dotc/core/ConstraintHandling.scala
@@ -197,8 +197,6 @@ trait ConstraintHandling {
finally constraint = saved
}
- protected def solvedConstraint = false
-
/** The current bounds of type parameter `param` */
final def bounds(param: PolyParam): TypeBounds = constraint.entry(param) match {
case bounds: TypeBounds => bounds
@@ -228,28 +226,24 @@ trait ConstraintHandling {
isSubTypeWhenFrozen(tp, bounds(param).lo)
final def canConstrain(param: PolyParam): Boolean =
- !frozenConstraint && !solvedConstraint && (constraint contains param)
+ !frozenConstraint && (constraint contains param)
+ /** Add constraint `param <: bond` if `fromBelow` is true, `param >: bound` otherwise.
+ * `bound` is assumed to be in normalized form, as specified in `firstTry` and
+ * `secondTry` of `TypeComparer`. In particular, it should not be an alias type,
+ * lazy ref, typevar, wildcard type, error type. In addition, upper bounds may
+ * not be AndTypes and lower bounds may not be OrTypes.
+ */
protected def addConstraint(param: PolyParam, bound: Type, fromBelow: Boolean): Boolean = {
def description = i"constr $param ${if (fromBelow) ">:" else "<:"} $bound:\n$constraint"
checkPropagated(s"adding $description")(true)
checkPropagated(s"added $description") {
addConstraintInvocations += 1
- try bound.dealias.stripTypeVar match {
+ try bound match {
case bound: PolyParam if constraint contains bound =>
if (fromBelow) addLess(bound, param) else addLess(param, bound)
- case bound: AndOrType if fromBelow != bound.isAnd =>
- addConstraint(param, bound.tp1, fromBelow) && addConstraint(param, bound.tp2, fromBelow)
- case bound: WildcardType =>
- bound.optBounds match {
- case TypeBounds(lo, hi) => addConstraint(param, if (fromBelow) lo else hi, fromBelow)
- case NoType => true
- }
- case bound: ErrorType =>
- true
case _ =>
- if (fromBelow) addLowerBound(param, bound)
- else addUpperBound(param, bound)
+ if (fromBelow) addLowerBound(param, bound) else addUpperBound(param, bound)
}
finally addConstraintInvocations -= 1
}