Skip to content

Commit 63b7598

Browse files
committed
Don't generate outer accessors for classes transitively nested in terms
Fixes #11367
1 parent 0273336 commit 63b7598

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,13 @@ object ExplicitOuter {
217217
cls.info.parents.exists(parent => // needs outer to potentially pass along to parent
218218
needsOuterIfReferenced(parent.classSymbol.asClass)))
219219

220-
/** Class is always instantiated in the compilation unit where it is defined */
220+
/** Class is only instantiated in the compilation unit where it is defined */
221221
private def hasLocalInstantiation(cls: ClassSymbol)(using Context): Boolean =
222222
// Modules are normally locally instantiated, except if they are declared in a trait,
223223
// in which case they will be instantiated in the classes that mix in the trait.
224-
cls.owner.isTerm || cls.is(Private, butNot = Module) || (cls.is(Module) && !cls.owner.is(Trait))
224+
cls.ownersIterator.takeWhile(!_.isStatic).exists(_.isTerm)
225+
|| cls.is(Private, butNot = Module)
226+
|| cls.is(Module) && !cls.owner.is(Trait)
225227

226228
/** The outer parameter accessor of cass `cls` */
227229
private def outerParamAccessor(cls: ClassSymbol)(using Context): TermSymbol =

tests/pos/i11367.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class C {
2+
def foo = {
3+
class D {
4+
class E
5+
}
6+
class F
7+
}
8+
}

0 commit comments

Comments
 (0)