From 483c845c078413b73ebb0b7e03b1c8c142bacac9 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Thu, 23 Nov 2017 17:26:00 +0100 Subject: [PATCH 1/2] Fix #3543: compare extractor with TermRef instead of MethodType --- .../tools/dotc/transform/patmat/Space.scala | 4 +- tests/patmat/3543.scala | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests/patmat/3543.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 3f9f7d3143af..bce2752d7164 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -400,9 +400,9 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { if (fun.symbol.owner == scalaSeqFactoryClass) projectSeq(pats) else - Prod(pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, projectSeq(pats) :: Nil, irrefutable(fun)) + Prod(pat.tpe.stripAnnots, fun.tpe, fun.symbol, projectSeq(pats) :: Nil, irrefutable(fun)) else - Prod(pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, pats.map(project), irrefutable(fun)) + Prod(pat.tpe.stripAnnots, fun.tpe, fun.symbol, pats.map(project), irrefutable(fun)) case Typed(pat @ UnApply(_, _, _), _) => project(pat) case Typed(expr, tpt) => Typ(erase(expr.tpe.stripAnnots), true) diff --git a/tests/patmat/3543.scala b/tests/patmat/3543.scala new file mode 100644 index 000000000000..ce93b01c1840 --- /dev/null +++ b/tests/patmat/3543.scala @@ -0,0 +1,52 @@ +class Test { + class Foo { + def unapply(x: String): Option[String] = ??? + } + + def test(xs: List[String]): Unit = { + val Yes = new Foo + val No = new Foo + + xs match { + case Yes(x) :: ls => println("Yes") + case No(y) :: ls => println("No") // unreachable code + case _ => + } + } +} + +class Test2 { + class Foo(x: Boolean) { + def unapply(y: String): Boolean = x + } + + def test(xs: List[String]): Unit = { + val Yes = new Foo(true) + val No = new Foo(false) + + xs match { + case No() :: ls => println("No") + case Yes() :: ls => println("Yes") // unreachable code + case _ => + } + } +} + +class Test3 { + import scala.util.matching.Regex + + def main(args: Array[String]): Unit = { + foo("c" :: Nil, false) + } + + def foo(remaining: List[String], inCodeBlock: Boolean): Unit = { + remaining match { + case CodeBlockEndRegex(before) :: ls => + case SymbolTagRegex(name) :: ls if !inCodeBlock => println("OK") + case _ => + } + } + + val CodeBlockEndRegex = new Regex("(b)") + val SymbolTagRegex = new Regex("(c)") +} From e41b2bacdc4446bc5cadcc31c2923c00e20df38d Mon Sep 17 00:00:00 2001 From: Fengyun Liu Date: Thu, 23 Nov 2017 18:21:37 +0100 Subject: [PATCH 2/2] remove obsolete comment --- tests/patmat/3543.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/patmat/3543.scala b/tests/patmat/3543.scala index ce93b01c1840..c3659db431e6 100644 --- a/tests/patmat/3543.scala +++ b/tests/patmat/3543.scala @@ -9,7 +9,7 @@ class Test { xs match { case Yes(x) :: ls => println("Yes") - case No(y) :: ls => println("No") // unreachable code + case No(y) :: ls => println("No") case _ => } } @@ -26,7 +26,7 @@ class Test2 { xs match { case No() :: ls => println("No") - case Yes() :: ls => println("Yes") // unreachable code + case Yes() :: ls => println("Yes") case _ => } }