Skip to content

Commit 89e8ff9

Browse files
committed
refine patmat check for type erasure
1 parent da9511d commit 89e8ff9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
251251
Typ(tp.widenTermRefExpr.stripAnnots, false)
252252
else
253253
Var(pat.symbol, tp)
254-
case tp => Typ(tp, false)
254+
case tp => Typ(erase(tp), false)
255255
}
256256
case Alternative(trees) => Or(trees.map(project(_, roundUp)))
257257
case Bind(_, pat) => project(pat)
@@ -261,11 +261,22 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
261261
else if (roundUp) Typ(pat.tpe.stripAnnots, false)
262262
else Empty
263263
case Typed(pat @ UnApply(_, _, _), _) => project(pat)
264-
case Typed(expr, _) => Typ(expr.tpe.stripAnnots, true)
264+
case Typed(expr, _) => Typ(erase(expr.tpe.stripAnnots), true)
265265
case _ =>
266266
Empty
267267
}
268268

269+
/* Erase a type binding according to erasure rule */
270+
def erase(tp: Type): Type = {
271+
def doErase(tp: Type): Type = tp match {
272+
case tp: RefinedType => erase(tp.parent)
273+
case _ => tp
274+
}
275+
276+
val origin = doErase(tp)
277+
if (origin =:= defn.ArrayType) tp else origin
278+
}
279+
269280
/** Is `tp1` a subtype of `tp2`? */
270281
def isSubType(tp1: Type, tp2: Type): Boolean = tp1 <:< tp2
271282

tests/patmat/t2425.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait B
2+
class D extends B
3+
object Test extends App {
4+
def foo[T](bar: T) = {
5+
bar match {
6+
case _: Array[Array[_]] => println("array 2d")
7+
case _: Array[_] => println("array 1d")
8+
case _ => println("something else")
9+
}
10+
}
11+
foo(Array.fill(10)(2))
12+
foo(Array.fill(10, 10)(2))
13+
foo(Array.fill(10, 10, 10)(2))
14+
foo(List(1, 2, 3))
15+
}

0 commit comments

Comments
 (0)