8000 More robust outer test for patmat · scala/scala@80ce231 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80ce231

Browse files
committed
More robust outer test for patmat
While investigating scala/scala-dev#251
1 parent 014ebc4 commit 80ce231

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,15 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
337337
def eqTest(pat: Tree, testedBinder: Symbol) = REF(testedBinder) OBJ_EQ pat
338338

339339
def outerTest(testedBinder: Symbol, expectedTp: Type): Tree = {
340-
val expectedOuter = expectedTp.prefix match {
341-
case ThisType(clazz) => This(clazz)
342-
case NoType => mkTRUE // fallback for SI-6183
343-
case pre => REF(pre.prefix, pre.termSymbol)
340+
val expectedPrefix = expectedTp.prefix
341+
if (expectedPrefix eq NoType) mkTRUE // fallback for SI-6183
342+
else {
343+
// ExplicitOuter replaces `Select(q, outerSym) OBJ_EQ expectedPrefix` by `Select(q, outerAccessor(outerSym.owner)) OBJ_EQ expectedPrefix`
344+
// if there's an outer accessor, otherwise the condition becomes `true` -- TODO: can we improve needsOuterTest so there's always an outerAccessor?
345+
val outerFor = expectedTp.typeSymbol
346+
val outerMarker = outerFor.newMethod(vpmName.outer, newFlags = SYNTHETIC | ARTIFACT) setInfo expectedPrefix
347+
Select(codegen._asInstanceOf(testedBinder, expectedTp), outerMarker) OBJ_EQ gen.mkAttributedQualifier(expectedPrefix)
344348
}
345-
346-
// ExplicitOuter replaces `Select(q, outerSym) OBJ_EQ expectedPrefix` by `Select(q, outerAccessor(outerSym.owner)) OBJ_EQ expectedPrefix`
347-
// if there's an outer accessor, otherwise the condition becomes `true` -- TODO: can we improve needsOuterTest so there's always an outerAccessor?
348-
val outer = expectedTp.typeSymbol.newMethod(vpmName.outer, newFlags = SYNTHETIC | ARTIFACT) setInfo expectedTp.prefix
349-
350-
(Select(codegen._asInstanceOf(testedBinder, expectedTp), outer)) OBJ_EQ expectedOuter
351349
}
352350
}
353351

0 commit comments

Comments
 (0)
0