diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-31 03:58:53 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-31 03:58:53 -0700 |
commit | 72d213d65a94e32f833b8c47d6f17539258ffc77 (patch) | |
tree | 8140d29fd88137b2c5ea9a7f80d8601e047cac7f | |
parent | 8b9269313637ae3e65f6048d4b1615d1e64963d9 (diff) | |
download | scala-72d213d65a94e32f833b8c47d6f17539258ffc77.tar.gz scala-72d213d65a94e32f833b8c47d6f17539258ffc77.tar.bz2 scala-72d213d65a94e32f833b8c47d6f17539258ffc77.zip |
New method typeRelationPreCheck.
Utilizes TriState from previous commit. Consolidates code
which had been duplicated across isSubType and isSameType.
-rw-r--r-- | src/reflect/scala/reflect/internal/tpe/TypeComparers.scala | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala b/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala index 711a94d7bd..0cbe49fae2 100644 --- a/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala +++ b/src/reflect/scala/reflect/internal/tpe/TypeComparers.scala @@ -4,7 +4,7 @@ package internal package tpe import scala.collection.{ mutable } -import util.Statistics +import util.{ Statistics, TriState } import scala.annotation.tailrec trait TypeComparers { @@ -294,6 +294,32 @@ trait TypeComparers { // if (subsametypeRecursions == 0) undoLog.clear() } + /** Check whether the subtype or type equivalence relationship + * between the argument is predetermined. Returns a tri-state + * value: True means the arguments are always sub/same types, + * False means they never are, and Unknown means the caller + * will have to figure things out. + */ + private def typeRelationPreCheck(tp1: Type, tp2: Type): TriState = { + def isTrue = ( + (tp1 eq tp2) + || isErrorOrWildcard(tp1) + || isErrorOrWildcard(tp2) + || (tp1 eq NoPrefix) && tp2.typeSymbol.isPackageClass // !! I do not see how this would be warranted by the spec + || (tp2 eq NoPrefix) && tp1.typeSymbol.isPackageClass // !! I do not see how this would be warranted by the spec + ) + // isFalse, assuming !isTrue + def isFalse = ( + (tp1 eq NoType) + || (tp2 eq NoType) + || (tp1 eq NoPrefix) + || (tp2 eq NoPrefix) + ) + + if (isTrue) TriState.True + else if (isFalse) TriState.False + else TriState.Unknown + } private def isPolySubType(tp1: PolyType, tp2: PolyType): Boolean = { val PolyType(tparams1, res1) = tp1 val PolyType(tparams2, res2) = tp2 |