Skip to content

Commit a0ad3f1

Browse files
authored
Merge pull request #1398 from dotty-staging/fix-#1269
Fix #1269: Typing and pattern matching of nested subclasses
2 parents ed05cba + 3c3b323 commit a0ad3f1

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,10 +2995,6 @@ object Types {
29952995
/** The class type with all type parameters */
29962996
def fullyAppliedRef(implicit ctx: Context): Type = fullyAppliedRef(cls.typeRef, cls.typeParams)
29972997

2998-
def rebase(tp: Type)(implicit ctx: Context): Type =
2999-
if ((prefix eq cls.owner.thisType) || !cls.owner.isClass || ctx.erasedTypes) tp
3000-
else tp.substThis(cls.owner.asClass, prefix)
3001-
30022998
private var typeRefCache: TypeRef = null
30032999

30043000
def typeRef(implicit ctx: Context): TypeRef = {
@@ -3018,7 +3014,7 @@ object Types {
30183014
/** The parent type refs as seen from the given prefix */
30193015
override def parents(implicit ctx: Context): List[TypeRef] = {
30203016
if (parentsCache == null)
3021-
parentsCache = cls.classParents.mapConserve(rebase(_).asInstanceOf[TypeRef])
3017+
parentsCache = cls.classParents.mapConserve(_.asSeenFrom(prefix, cls.owner).asInstanceOf[TypeRef])
30223018
parentsCache
30233019
}
30243020

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
763763

764764
def outerTest(testedBinder: Symbol, expectedTp: Type): Tree = {
765765
val expectedOuter = expectedTp.normalizedPrefix match {
766-
//case ThisType(clazz) => This(clazz)
767766
//case NoType => Literal(Constant(true)) // fallback for SI-6183 todo?
768-
case pre => ref(pre.termSymbol)
767+
case pre: SingletonType => singleton(pre)
769768
}
770769

771770
// ExplicitOuter replaces `Select(q, outerSym) OBJ_EQ expectedPrefix` by `Select(q, outerAccessor(outerSym.owner)) OBJ_EQ expectedPrefix`

tests/pos/i1269.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Module {
2+
sealed abstract class Tree
3+
4+
case class LetL() extends Tree
5+
6+
object O {
7+
case class LetR() extends Tree
8+
}
9+
}
10+
11+
class Patmat(val module: Module) {
12+
def patmat(tree: module.Tree) = tree match {
13+
case module.LetL() =>
14+
case module.O.LetR() =>
15+
}
16+
}

0 commit comments

Comments
 (0)