Skip to content

Commit 9fef766

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 9763842 commit 9fef766

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
@@ -213,9 +213,9 @@ object ExplicitOuter {
213213

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

220220
/** The outer parameter accessor of cass `cls` */
221221
private def outerParamAccessor(cls: ClassSymbol)(implicit ctx: Context): TermSymbol =

0 commit comments

Comments
 (0)