aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-01-14 18:36:20 +0100
committerMartin Odersky <odersky@gmail.com>2015-01-14 19:07:43 +0100
commit1a6cc683f37ea9f57454d1d7f62ac975c98c2a94 (patch)
treed7a4792954130fbd5e64b7180a969b169a4e88c9
parentdec46172ea9f38e3f1d9aeaac8e2984c6ea3a878 (diff)
downloaddotty-1a6cc683f37ea9f57454d1d7f62ac975c98c2a94.tar.gz
dotty-1a6cc683f37ea9f57454d1d7f62ac975c98c2a94.tar.bz2
dotty-1a6cc683f37ea9f57454d1d7f62ac975c98c2a94.zip
Rename isConstrained -> canConstrain for clarity
Plus some more comments explaining aspects of isSubType.
-rw-r--r--src/dotty/tools/dotc/core/ConstraintHandling.scala2
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala16
2 files changed, 13 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/ConstraintHandling.scala b/src/dotty/tools/dotc/core/ConstraintHandling.scala
index c3243f5d9..96174ad1c 100644
--- a/src/dotty/tools/dotc/core/ConstraintHandling.scala
+++ b/src/dotty/tools/dotc/core/ConstraintHandling.scala
@@ -229,7 +229,7 @@ trait ConstraintHandling {
res
}
- final def isConstrained(param: PolyParam): Boolean =
+ final def canConstrain(param: PolyParam): Boolean =
!frozenConstraint && !solvedConstraint && (constraint contains param)
/** Test whether the lower bounds of all parameters in this
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index f3518eff2..4bb061aab 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -184,7 +184,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
if (solvedConstraint && (constraint contains tp2)) isSubType(tp1, bounds(tp2).lo)
else
constraintImpliesSuper(tp2, tp1) || {
- if (isConstrained(tp2)) addConstraint(tp2, tp1.widenExpr, fromBelow = true)
+ if (canConstrain(tp2)) addConstraint(tp2, tp1.widenExpr, fromBelow = true)
else (ctx.mode is Mode.TypevarsMissContext) || secondTry(tp1, tp2)
}
}
@@ -246,7 +246,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
if (solvedConstraint && (constraint contains tp1)) isSubType(bounds(tp1).lo, tp2)
else
constraintImpliesSub(tp1, tp2) || {
- if (isConstrained(tp1))
+ if (canConstrain(tp1))
addConstraint(tp1, tp2, fromBelow = false) && {
if ((!frozenConstraint) &&
(tp2 isRef defn.NothingClass) &&
@@ -449,6 +449,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
case tp2i: TermRef =>
isSubType(tp1, tp2i)
case ExprType(tp2i: TermRef) if (ctx.phase.id > ctx.gettersPhase.id) =>
+ // After getters, val x: T becomes def x: T
isSubType(tp1, tp2i)
case _ =>
false
@@ -516,10 +517,15 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
false
} else isSubType(tp1, tp2)
+ /** Does type `tp1` have a member with name `name` whose normalized type is a subtype of
+ * the normalized type of the refinement `tp2`?
+ * Normalization is as follows: If `tp2` contains a skolem to its refinement type,
+ * rebase both itself and the member info of `tp` on a freshly created skolem type.
+ */
protected def hasMatchingMember(name: Name, tp1: Type, tp2: RefinedType): Boolean = {
val saved = skolemsOutstanding
try {
- def rebindNeeded = tp2.refinementRefersToThis
+ val rebindNeeded = tp2.refinementRefersToThis
val base = if (rebindNeeded) ensureSingleton(tp1) else tp1
val rinfo2 = if (rebindNeeded) tp2.refinedInfo.substSkolem(tp2, base) else tp2.refinedInfo
def qualifies(m: SingleDenotation) = isSubType(m.info, rinfo2)
@@ -531,7 +537,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling wi
memberMatches(base member name) ||
tp1.isInstanceOf[SingletonType] &&
{ // special case for situations like:
- // foo <: C { type T = foo.T }
+ // class C { type T }
+ // val foo: C
+ // foo.type <: C { type T = foo.T }
rinfo2 match {
case rinfo2: TypeAlias =>
!ctx.phase.erasedTypes && (base select name) =:= rinfo2.alias