Skip to content

Commit b129332

Browse files
committed
Move explicit outer after pattern matching
But allow pattern matching to provide outer accessors when needed using with ensureOuterAccessors.
1 parent c3078b1 commit b129332

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ class Compiler {
5454
new ElimRepeated,
5555
new ElimLocals),
5656
List(new ExtensionMethods),
57-
List(new TailRec, new ExplicitOuter),
57+
List(new TailRec),
5858
List(new PatternMatcher,
59+
new ExplicitOuter,
5960
// new LazyValTranformContext().transformer, // disabled, awaiting fixes
6061
new Splitter),
6162
List(new ElimByName,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransf
6969
private def newOuterAccessors(cls: ClassSymbol)(implicit ctx: Context) =
7070
newOuterAccessor(cls, cls) :: (if (cls is Trait) Nil else newOuterParamAccessor(cls) :: Nil)
7171

72+
/** Ensure that class `cls` has outer accessors */
73+
def ensureOuterAccessors(cls: ClassSymbol)(implicit ctx: Context): Unit = {
74+
if (!hasOuter(cls)) newOuterAccessors(cls).foreach(_.enteredAfter(thisTransformer))
75+
}
76+
7277
/** First, add outer accessors if a class does not have them yet and it references an outer this.
7378
* If the class has outer accessors, implement them.
7479
* Furthermore, if a parent trait might have an outer accessor,
@@ -86,7 +91,7 @@ class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransf
8691
if (needsOuterIfReferenced(cls) &&
8792
!needsOuterAlways(cls) &&
8893
impl.existsSubTree(referencesOuter(cls, _)))
89-
newOuterAccessors(cls).foreach(_.enteredAfter(thisTransformer))
94+
ensureOuterAccessors(cls)
9095
if (hasOuter(cls)) {
9196
val newDefs = new mutable.ListBuffer[Tree]
9297
if (isTrait)

0 commit comments

Comments
 (0)