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..c3659db431e6 --- /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") + 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") + 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)") +}