From 9fa65772dafb274741b7b6f7a8a8082ddd4dea50 Mon Sep 17 00:00:00 2001 From: Jasper Moeys Date: Mon, 30 Aug 2021 12:50:08 +0200 Subject: [PATCH] support AppliedType in outerTestNeeded --- .../tools/dotc/transform/PatternMatcher.scala | 11 +++++--- tests/run/t13418.check | 3 +++ tests/run/t13418.scala | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/run/t13418.check create mode 100644 tests/run/t13418.scala diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 536c566bfead..5a640c8f1d98 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -719,16 +719,19 @@ object PatternMatcher { val expectedTp = tpt.tpe // An outer test is needed in a situation like `case x: y.Inner => ...` - def outerTestNeeded: Boolean = - // See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest` - // generates an outer test based on `patType.prefix` with automatically dealises. - expectedTp.dealias match { + def outerTestNeeded: Boolean = { + def go(expected: Type): Boolean = expected match { case tref @ TypeRef(pre: SingletonType, _) => tref.symbol.isClass && ExplicitOuter.needsOuterIfReferenced(tref.symbol.asClass) + case AppliedType(tpe, _) => go(tpe) case _ => false } + // See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest` + // generates an outer test based on `patType.prefix` with automatically dealises. + go(expectedTp.dealias) + } def outerTest: Tree = thisPhase.transformFollowingDeep { val expectedOuter = singleton(expectedTp.normalizedPrefix) diff --git a/tests/run/t13418.check b/tests/run/t13418.check new file mode 100644 index 000000000000..7614df8ec464 --- /dev/null +++ b/tests/run/t13418.check @@ -0,0 +1,3 @@ +ok +ok +ok diff --git a/tests/run/t13418.scala b/tests/run/t13418.scala new file mode 100644 index 000000000000..344bae8a274b --- /dev/null +++ b/tests/run/t13418.scala @@ -0,0 +1,26 @@ +class A { class B } +val a1 = new A +val a2 = new A +val b: Any = new a1.B + +class X { class Y[Q] } +val x1 = new X +val x2 = new X +val y: Any = new x1.Y[Int] +type Foo = [Q] =>> x2.Y[Q] +type Bar = [Q] =>> x1.Y[Q] + +@main def Test() = { + b match { + case _: a2.B => println("wrong") + case _: a1.B => println("ok") + } + y match { + case _: x2.Y[_] => println("wrong") + case _: x1.Y[_] => println("ok") + } + y match { + case _: Foo[_] => println("wrong") + case _: Bar[_] => println("ok") + } +}