Skip to content

Commit d7bea54

Browse files
committed
Modules in traits always get an outer pointer.
They will be instantiated in the classes that mix in their owner trait.
1 parent d682455 commit d7bea54

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ object ExplicitOuter {
215215

216216
/** Class is always instantiated in the compilation unit where it is defined */
217217
private def hasLocalInstantiation(cls: ClassSymbol)(using Context): Boolean =
218-
// scala2x modules always take an outer pointer(as of 2.11)
219-
// dotty modules are always locally instantiated
220-
cls.owner.isTerm || cls.is(Private) || cls.is(Module, butNot = Scala2x)
218+
// Modules are normally locally instantiated, except if they are declared in a trait,
219+
// in which case they will be instantiated in the classes that mix in the trait.
220+
cls.owner.isTerm || cls.is(Private, butNot = Module) || (cls.is(Module) && !cls.owner.is(Trait))
221221

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

0 commit comments

Comments
 (0)