Skip to content

Commit af1bde2

Browse files
committed
Fix handling of private trait objects
1 parent 2e46d55 commit af1bde2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Contexts.Context
99
import dotty.tools.dotc.core.Decorators._
1010
import dotty.tools.dotc.core.DenotTransformers.IdentityDenotTransformer
1111
import 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}
1313
import dotty.tools.dotc.core.StdNames.nme
1414
import dotty.tools.dotc.core.Symbols._
1515
import dotty.tools.dotc.core.Types._
@@ -73,11 +73,18 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
7373
else {
7474
val isField = sym.owner.isClass
7575
if (isField)
76-
if sym.isAllOf(SyntheticModule) && sym.allOverriddenSymbols.isEmpty then
76+
if sym.isAllOf(SyntheticModule)
77+
&& sym.allOverriddenSymbols.isEmpty
78+
&& !sym.name.is(ExpandedName) then
7779
// I am not sure what the conditions for this optimization should be.
7880
// It was applied for all synthetic objects, but this is clearly false, as t704 demonstrates.
7981
// It seems we have to at least exclude synthetic objects that derive from mixins.
8082
// 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.
8188
transformSyntheticModule(tree)
8289
else if (sym.isThreadUnsafe || ctx.settings.scalajs.value)
8390
if (sym.is(Module) && !ctx.settings.scalajs.value) {

0 commit comments

Comments
 (0)