Skip to content

Commit f5a94f7

Browse files
committed
Merge pull request #754 from dotty-staging/fix-objects
Fixes to emission of static initializers and forwarders in backend.
2 parents 9eb55f1 + 945fefb commit f5a94f7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,8 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{
622622
def isSynchronized: Boolean = sym is Flags.Synchronized
623623
def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other)
624624
def hasAnnotation(ann: Symbol): Boolean = toDenot(sym).hasAnnotation(ann)
625-
def shouldEmitForwarders: Boolean = //exitingPickler { !(sym.name.toString contains '$')
626-
(sym is Flags.Module) && !(sym is Flags.ImplClass) /// !sym.isNestedClass
625+
def shouldEmitForwarders: Boolean =
626+
(sym is Flags.Module) && !(sym is Flags.ImplClass) && sym.isStatic
627627
def isJavaEntryPoint: Boolean = CollectEntryPoints.isJavaEntryPoint(sym)
628628

629629
def isClassConstructor: Boolean = toDenot(sym).isClassConstructor
@@ -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)