diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/Patterns.scala | 9 | ||||
-rw-r--r-- | test/files/run/bug3050.scala | 9 |
2 files changed, 17 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) } } diff --git a/test/files/run/bug3050.scala b/test/files/run/bug3050.scala new file mode 100644 index 0000000000..aaec99ec14 --- /dev/null +++ b/test/files/run/bug3050.scala @@ -0,0 +1,9 @@ +object Test { + def main(args: Array[String]): Unit = { + val x = + try { ("": Any) match { case List(_*) => true } } + catch { case _ => false } + + assert(x == false) + } +} |