Skip to content

Commit 8c3e7a2

Browse files
authored
Merge pull request #13420 from Jasper-M/fix/13418
Fix #13418: support AppliedType in outerTestNeeded
2 parents b81f50f + 9fa6577 commit 8c3e7a2

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -719,16 +719,19 @@ object PatternMatcher {
719719
val expectedTp = tpt.tpe
720720

721721
// An outer test is needed in a situation like `case x: y.Inner => ...`
722-
def outerTestNeeded: Boolean =
723-
// See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest`
724-
// generates an outer test based on `patType.prefix` with automatically dealises.
725-
expectedTp.dealias match {
722+
def outerTestNeeded: Boolean = {
723+
def go(expected: Type): Boolean = expected match {
726724
case tref @ TypeRef(pre: SingletonType, _) =>
727725
tref.symbol.isClass &&
728726
ExplicitOuter.needsOuterIfReferenced(tref.symbol.asClass)
727+
case AppliedType(tpe, _) => go(tpe)
729728
case _ =>
730729
false
731730
}
731+
// See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest`
732+
// generates an outer test based on `patType.prefix` with automatically dealises.
733+
go(expectedTp.dealias)
734+
}
732735

733736
def outerTest: Tree = thisPhase.transformFollowingDeep {
734737
val expectedOuter = singleton(expectedTp.normalizedPrefix)

tests/run/t13418.check

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ok
2+
ok
3+
ok

tests/run/t13418.scala

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class A { class B }
2+
val a1 = new A
3+
val a2 = new A
4+
val b: Any = new a1.B
5+
6+
class X { class Y[Q] }
7+
val x1 = new X
8+
val x2 = new X
9+
val y: Any = new x1.Y[Int]
10+
type Foo = [Q] =>> x2.Y[Q]
11+
type Bar = [Q] =>> x1.Y[Q]
12+
13+
@main def Test() = {
14+
b match {
15+
case _: a2.B => println("wrong")
16+
case _: a1.B => println("ok")
17+
}
18+
y match {
19+
case _: x2.Y[_] => println("wrong")
20+
case _: x1.Y[_] => println("ok")
21+
}
22+
y match {
23+
case _: Foo[_] => println("wrong")
24+
case _: Bar[_] => println("ok")
25+
}
26+
}

0 commit comments

Comments
 (0)