From da79f1b5fb171972704df6738ee2d9a17da4c8dc Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Mon, 10 Dec 2007 23:47:50 +0000 Subject: better approximation of <:<_erased, fixes bug i... better approximation of <:<_erased, fixes bug in PrettyPrinter (oddly) --- src/compiler/scala/tools/nsc/matching/ParallelMatching.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 32b95944e4..dffd1f3db9 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -682,10 +682,17 @@ trait ParallelMatching { } } + /** an approximation of _tp1 <:< tp2 that ignores _ types. this code is wrong, + * ideally there is a better way to do it, and ideally defined in Types.scala + */ def subsumes_erased(_tp1:Type, tp2:Type) = { val tp1 = patternType_wrtEquals(_tp1) tp1.isInstanceOf[TypeRef] && tp2.isInstanceOf[TypeRef] && - ((tp1.prefix =:= tp2.prefix) && (tp1.typeSymbol eq tp2.typeSymbol) && (tp1.typeSymbol ne definitions.ArrayClass)) + ((tp1.prefix =:= tp2.prefix) && + ((tp1.typeSymbol eq tp2.typeSymbol) && + (tp1.typeSymbol ne definitions.ArrayClass)) || + tp1.parents.exists(_.typeSymbol eq tp2.typeSymbol)) + // rather: tp1.baseTypes.exists...? } /** returns true if pattern tests an object */ @@ -706,7 +713,6 @@ trait ParallelMatching { val pat = pats.head val strippedPattern = strip2(pat) val patternType = strippedPattern.tpe - sr = strippedPattern match { case Literal(Constant(null)) if !(headPatternType =:= patternType) => //special case for constant null pattern (ms,ss,(j,pat)::rs); @@ -725,7 +731,7 @@ trait ParallelMatching { case qq if subsumes_erased(patternType, headPatternType) || (patternType_wrtEquals(patternType) <:< headPatternType) && !isDefaultPattern(pat) => ({if (pat.tpe =:= headPatternType /*never true for */) EmptyTree else pat}::ms, (j,subpatterns(pat))::ss, rs); - case _ if (headPatternType <:< patternType /*never true for */) || isDefaultPattern(pat) => + case _ if subsumes_erased(headPatternType, patternType) || (headPatternType <:< patternType /*never true for */) || isDefaultPattern(pat) => (EmptyTree::ms, (j, dummies)::ss, (j,pat)::rs) // subsuming (matched *and* remaining pattern) case _ => -- cgit v1.2.3