summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-05-20 16:30:59 +0000
committerPaul Phillips <paulp@improving.org>2010-05-20 16:30:59 +0000
commit136f08e7db582060142c9ac796ba0b71df74139f (patch)
tree0cba76b29d9e24c7a683d13d5efee65a25a1f565 /src
parentdba07aa5a45ba53ecfeef8e42b8b4362b0fecd83 (diff)
downloadscala-136f08e7db582060142c9ac796ba0b71df74139f.tar.gz
scala-136f08e7db582060142c9ac796ba0b71df74139f.tar.bz2
scala-136f08e7db582060142c9ac796ba0b71df74139f.zip
Misoptimization for list extractors caused non-...
Misoptimization for list extractors caused non-sequences to incorrectly match. Closes #3050, #2800. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/matching/Patterns.scala9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/Patterns.scala b/src/compiler/scala/tools/nsc/matching/Patterns.scala
index b1bcf44c38..14e940d8a9 100644
--- a/src/compiler/scala/tools/nsc/matching/Patterns.scala
+++ b/src/compiler/scala/tools/nsc/matching/Patterns.scala
@@ -314,13 +314,20 @@ trait Patterns extends ast.TreeDSL {
object UnapplyPattern {
private object UnapplySeq {
+ /** This is as far as I can tell an elaborate attempt to spot case List(...) and
+ * avoid the extractor penalty. It has led to some bugs (e.g. 2800, 3050) which
+ * I attempt to address below.
+ */
private object TypeApp {
def unapply(x: Any) = condOpt(x) {
case TypeApply(sel @ Select(stor, nme.unapplySeq), List(tpe)) if stor.symbol eq ListModule => tpe
}
}
def unapply(x: UnApply) = condOpt(x) {
- case UnApply(Apply(TypeApp(tptArg), _), List(ArrayValue(_, xs))) => (tptArg, xs)
+ case UnApply(Apply(TypeApp(tptArg), _), List(ArrayValue(_, xs)))
+ // make sure it's not empty or only _*, as otherwise the rewrite
+ // also removes the instance check.
+ if xs takeWhile (x => !isStar(x)) nonEmpty => (tptArg, xs)
}
}