From 72d213d65a94e32f833b8c47d6f17539258ffc77 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 31 May 2013 03:58:53 -0700 Subject: New method typeRelationPreCheck. Utilizes TriState from previous commit. Consolidates code which had been duplicated across isSubType and isSameType. --- .../scala/reflect/internal/tpe/TypeComparers.scala | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/reflect') 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 -- cgit v1.2.3