@@ -3,6 +3,7 @@ package dotc
33package transform
44
55import MegaPhase .*
6+ import ast .tpd .*
67import core .DenotTransformers .*
78import core .Symbols .*
89import core .Contexts .*
@@ -15,10 +16,8 @@ import core.Names.*
1516import core .NameOps .*
1617import core .NameKinds .SuperArgName
1718
18- import dotty .tools .dotc .ast .tpd
19-
20- import collection .mutable
2119import scala .annotation .tailrec
20+ import scala .collection .mutable
2221
2322/** This phase adds outer accessors to classes and traits that need them.
2423 * Compared to Scala 2.x, it tries to minimize the set of classes
@@ -36,7 +35,6 @@ import scala.annotation.tailrec
3635 */
3736class ExplicitOuter extends MiniPhase with InfoTransformer { thisPhase =>
3837 import ExplicitOuter .*
39- import ast .tpd .*
4038
4139 override def phaseName : String = ExplicitOuter .name
4240
@@ -64,7 +62,7 @@ class ExplicitOuter extends MiniPhase with InfoTransformer { thisPhase =>
6462 * Furthermore, if a parent trait might have an outer accessor,
6563 * provide an implementation for the outer accessor by computing the parent's
6664 * outer from the parent type prefix. If the trait ends up not having an outer accessor
67- * after all, the implementation is redundant, but does not harm.
65+ * after all, the implementation is redundant, but does no harm.
6866 * The same logic is not done for non-trait parent classes because for them the outer
6967 * pointer is passed in the super constructor, which will be implemented later in
7068 * a separate phase which needs to run after erasure. However, we make sure here
@@ -111,7 +109,7 @@ class ExplicitOuter extends MiniPhase with InfoTransformer { thisPhase =>
111109 else impl
112110 }
113111
114- override def transformClosure (tree : Closure )(using Context ): tpd. Tree = {
112+ override def transformClosure (tree : Closure )(using Context ): Tree = {
115113 if (tree.tpt ne EmptyTree ) {
116114 val cls = tree.tpt.asInstanceOf [TypeTree ].tpe.classSymbol
117115 if (cls.exists && hasOuter(cls.asClass))
@@ -122,7 +120,6 @@ class ExplicitOuter extends MiniPhase with InfoTransformer { thisPhase =>
122120}
123121
124122object ExplicitOuter {
125- import ast .tpd .*
126123
127124 val name : String = " explicitOuter"
128125 val description : String = " add accessors to outer classes from nested ones"
@@ -217,11 +214,12 @@ object ExplicitOuter {
217214 * - we need to potentially pass along outer to a parent class or trait
218215 */
219216 private def needsOuterAlways (cls : ClassSymbol )(using Context ): Boolean =
220- needsOuterIfReferenced(cls) &&
221- (! hasOnlyLocalInstantiation(cls) || // needs outer because we might not know whether outer is referenced or not
222- cls.mixins.exists(needsOuterIfReferenced) || // needs outer for parent traits
223- cls.info.parents.exists(parent => // needs outer to potentially pass along to parent
224- needsOuterIfReferenced(parent.classSymbol.asClass)))
217+ needsOuterIfReferenced(cls)
218+ && (! hasOnlyLocalInstantiation(cls) // needs outer because we might not know whether outer is referenced or not
219+ || cls.mixins.exists(needsOuterIfReferenced) // needs outer for parent traits
220+ || cls.info.parents.exists: parent => // needs outer to potentially pass along to parent
221+ needsOuterIfReferenced(parent.classSymbol.asClass)
222+ )
225223
226224 /** Class is only instantiated in the compilation unit where it is defined */
227225 private def hasOnlyLocalInstantiation (cls : ClassSymbol )(using Context ): Boolean =
0 commit comments