Skip to content

Commit 96dfb35

Browse files
committed
Fix emission of static initialisers for Modules.
They should not be emitted for non-static modules. All modules look as if they were static by backend.
1 parent 9eb55f1 commit 96dfb35

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,16 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
632632
* True for module classes of modules that are top-level or owned only by objects. Module classes
633633
* for such objects will get a MODULE$ flag and a corresponding static initializer.
634634
*/
635-
def isStaticModuleClass: Boolean = sym.isStatic && (sym is Flags.Module)
635+
def isStaticModuleClass: Boolean =
636+
(sym is Flags.Module) && {
637+
// scalac uses atPickling here
638+
// this would not work if modules are created after pickling
639+
// for example by specialization
640+
val original = toDenot(sym).initial
641+
val validity = original.validFor
642+
val shiftedContext = ctx.withPhase(validity.phaseId)
643+
toDenot(sym)(shiftedContext).isStatic
644+
}
636645

637646
def isStaticConstructor: Boolean = isStaticMember && isClassConstructor
638647

0 commit comments

Comments
 (0)