Skip to content

Commit 3696732

Browse files
authored
Merge pull request scala#5632 from adriaanm/ticket/9114
SI-9114 Fix crasher in pattern matcher with type aliases
2 parents fac487e + 9165886 commit 3696732

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3891,7 +3891,7 @@ trait Types
38913891
* any corresponding non-variant type arguments of bt1 and bt2 are the same
38923892
*/
38933893
def isPopulated(tp1: Type, tp2: Type): Boolean = {
3894-
def isConsistent(tp1: Type, tp2: Type): Boolean = (tp1, tp2) match {
3894+
def isConsistent(tp1: Type, tp2: Type): Boolean = (tp1.dealias, tp2.dealias) match {
38953895
case (TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)) =>
38963896
assert(sym1 == sym2, (sym1, sym2))
38973897
( pre1 =:= pre2

test/files/run/t9114.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import annotation.unchecked
2+
3+
class Test {
4+
trait Two[A, B]
5+
type One[A] = Two[A,A]
6+
class View extends One[Any]
7+
8+
def checkAny(x: Some[One[Any]]) = x match { // okay
9+
case Some(_: View) => true
10+
case _ => false
11+
}
12+
def checkAbstract[A](x: Some[One[A]]) = x match { // okay
13+
case Some(_: View) => true
14+
case _ => false
15+
}
16+
17+
def checkExistential(x: Some[One[_]]) = x match {
18+
case Some(_: View) => true // compiler crash
19+
case _ => false
20+
}
21+
}
22+
23+
object Test {
24+
def main(args: Array[String]): Unit = {
25+
val t1 = new Test
26+
val t2 = new Test
27+
assert(t1.checkAny(Some(new t1.View)))
28+
assert(t1.checkAbstract(Some(new t1.View)))
29+
assert(t1.checkExistential(Some(new t1.View)))
30+
}
31+
}

0 commit comments

Comments
 (0)