From 6e723202409d69cd6e6399d58a9d4fb7b2b337d4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 17 Jul 2016 14:16:19 +0200 Subject: [PATCH 1/2] Fix computation of parent types of a classinfo. The previously used `rebase` did not rewrire outer this references. The right thing to do here is an asSeenFrom. --- src/dotty/tools/dotc/core/Types.scala | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 11da27265289..754757a7ff90 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2993,10 +2993,6 @@ object Types { /** The class type with all type parameters */ def fullyAppliedRef(implicit ctx: Context): Type = fullyAppliedRef(cls.typeRef, cls.typeParams) - def rebase(tp: Type)(implicit ctx: Context): Type = - if ((prefix eq cls.owner.thisType) || !cls.owner.isClass || ctx.erasedTypes) tp - else tp.substThis(cls.owner.asClass, prefix) - private var typeRefCache: TypeRef = null def typeRef(implicit ctx: Context): TypeRef = { @@ -3016,7 +3012,7 @@ object Types { /** The parent type refs as seen from the given prefix */ override def parents(implicit ctx: Context): List[TypeRef] = { if (parentsCache == null) - parentsCache = cls.classParents.mapConserve(rebase(_).asInstanceOf[TypeRef]) + parentsCache = cls.classParents.mapConserve(_.asSeenFrom(prefix, cls.owner).asInstanceOf[TypeRef]) parentsCache } From 3c3b32346f2c4eafe26cc9659b41ae50b0316b92 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 17 Jul 2016 18:29:30 +0200 Subject: [PATCH 2/2] Fix outer test in pattern matcher Previous test did not reflect deeper paths for outer references. This caused a -Ycheck:patMat failure for i1269.scala. --- .../tools/dotc/transform/PatternMatcher.scala | 3 +-- tests/pos/i1269.scala | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i1269.scala diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 974053769233..92d638be9913 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -763,9 +763,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans def outerTest(testedBinder: Symbol, expectedTp: Type): Tree = { val expectedOuter = expectedTp.normalizedPrefix match { - //case ThisType(clazz) => This(clazz) //case NoType => Literal(Constant(true)) // fallback for SI-6183 todo? - case pre => ref(pre.termSymbol) + case pre: SingletonType => singleton(pre) } // ExplicitOuter replaces `Select(q, outerSym) OBJ_EQ expectedPrefix` by `Select(q, outerAccessor(outerSym.owner)) OBJ_EQ expectedPrefix` diff --git a/tests/pos/i1269.scala b/tests/pos/i1269.scala new file mode 100644 index 000000000000..c0b56e1ea0e9 --- /dev/null +++ b/tests/pos/i1269.scala @@ -0,0 +1,16 @@ +trait Module { + sealed abstract class Tree + + case class LetL() extends Tree + + object O { + case class LetR() extends Tree + } +} + +class Patmat(val module: Module) { + def patmat(tree: module.Tree) = tree match { + case module.LetL() => + case module.O.LetR() => + } +}