@@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts.Context
99import dotty .tools .dotc .core .Decorators ._
1010import dotty .tools .dotc .core .DenotTransformers .IdentityDenotTransformer
1111import dotty .tools .dotc .core .Flags ._
12- import dotty .tools .dotc .core .NameKinds .{LazyBitMapName , LazyLocalInitName , LazyLocalName }
12+ import dotty .tools .dotc .core .NameKinds .{LazyBitMapName , LazyLocalInitName , LazyLocalName , ExpandedName }
1313import dotty .tools .dotc .core .StdNames .nme
1414import dotty .tools .dotc .core .Symbols ._
1515import dotty .tools .dotc .core .Types ._
@@ -73,7 +73,18 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
7373 else {
7474 val isField = sym.owner.isClass
7575 if (isField)
76- if (sym.isAllOf(SyntheticModule ))
76+ if sym.isAllOf(SyntheticModule )
77+ && sym.allOverriddenSymbols.isEmpty
78+ && ! sym.name.is(ExpandedName ) then
79+ // I am not sure what the conditions for this optimization should be.
80+ // It was applied for all synthetic objects, but this is clearly false, as t704 demonstrates.
81+ // It seems we have to at least exclude synthetic objects that derive from mixins.
82+ // This is done by demanding that the object does not override anything.
83+ // Figuring out whether a symbol implements a trait module is not so simple.
84+ // For non-private trait members we can check whether there is an overridden symbol.
85+ // For private trait members this does not work, since `ensureNotPrivate` in phase Mixins
86+ // does change the name but does not update the owner's scope, so `allOverriddenSymbols` does
87+ // not work in that case. However, we can check whether the name is an ExpandedName instead.
7788 transformSyntheticModule(tree)
7889 else if (sym.isThreadUnsafe || ctx.settings.scalajs.value)
7990 if (sym.is(Module ) && ! ctx.settings.scalajs.value) {
0 commit comments