Skip to content

Fix #13418: support AppliedType in outerTestNeeded #13420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might neeed to dealias here too if the constructor is an alias.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I added a test for that now.

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)
Expand Down
3 changes: 3 additions & 0 deletions tests/run/t13418.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ok
ok
ok
26 changes: 26 additions & 0 deletions tests/run/t13418.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}