Skip to content

Commit 7fa8a93

Browse files
Merge pull request #3545 from dotty-staging/fix-3543
Fix #3543: compare extractor with TermRef instead of MethodType
2 parents 6cceefc + e41b2ba commit 7fa8a93

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
400400
if (fun.symbol.owner == scalaSeqFactoryClass)
401401
projectSeq(pats)
402402
else
403-
Prod(pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, projectSeq(pats) :: Nil, irrefutable(fun))
403+
Prod(pat.tpe.stripAnnots, fun.tpe, fun.symbol, projectSeq(pats) :: Nil, irrefutable(fun))
404404
else
405-
Prod(pat.tpe.stripAnnots, fun.tpe.widen, fun.symbol, pats.map(project), irrefutable(fun))
405+
Prod(pat.tpe.stripAnnots, fun.tpe, fun.symbol, pats.map(project), irrefutable(fun))
406406
case Typed(pat @ UnApply(_, _, _), _) => project(pat)
407407
case Typed(expr, tpt) =>
408408
Typ(erase(expr.tpe.stripAnnots), true)

tests/patmat/3543.scala

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
class Test {
2+
class Foo {
3+
def unapply(x: String): Option[String] = ???
4+
}
5+
6+
def test(xs: List[String]): Unit = {
7+
val Yes = new Foo
8+
val No = new Foo
9+
10+
xs match {
11+
case Yes(x) :: ls => println("Yes")
12+
case No(y) :: ls => println("No")
13+
case _ =>
14+
}
15+
}
16+
}
17+
18+
class Test2 {
19+
class Foo(x: Boolean) {
20+
def unapply(y: String): Boolean = x
21+
}
22+
23+
def test(xs: List[String]): Unit = {
24+
val Yes = new Foo(true)
25+
val No = new Foo(false)
26+
27+
xs match {
28+
case No() :: ls => println("No")
29+
case Yes() :: ls => println("Yes")
30+
case _ =>
31+
}
32+
}
33+
}
34+
35+
class Test3 {
36+
import scala.util.matching.Regex
37+
38+
def main(args: Array[String]): Unit = {
39+
foo("c" :: Nil, false)
40+
}
41+
42+
def foo(remaining: List[String], inCodeBlock: Boolean): Unit = {
43+
remaining match {
44+
case CodeBlockEndRegex(before) :: ls =>
45+
case SymbolTagRegex(name) :: ls if !inCodeBlock => println("OK")
46+
case _ =>
47+
}
48+
}
49+
50+
val CodeBlockEndRegex = new Regex("(b)")
51+
val SymbolTagRegex = new Regex("(c)")
52+
}

0 commit comments

Comments
 (0)