Skip to content

Commit 710e13d

Browse files
committed
Fix #3634: Lazily evaluate static module accessors
We did not use lazy evaluation for static objects, because these are usually evauated lazily by the backend. But that does not hold if the static module is an (accessor) def instead of a val.
1 parent 2164c42 commit 710e13d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
3636
class OffsetInfo(var defs: List[Tree], var ord:Int)
3737
val appendOffsetDefs = mutable.Map.empty[Symbol, OffsetInfo]
3838

39-
override def phaseName: String = "LazyVals"
39+
override def phaseName: String = "lazyVals"
4040

4141
/** List of names of phases that should have finished processing of tree
4242
* before this phase starts processing same tree */
@@ -61,7 +61,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
6161

6262
def transformLazyVal(tree: ValOrDefDef)(implicit ctx: Context): Tree = {
6363
val sym = tree.symbol
64-
if (!(sym is Flags.Lazy) || sym.owner.is(Flags.Trait) || (sym.isStatic && sym.is(Flags.Module))) tree
64+
if (!(sym is Flags.Lazy) ||
65+
sym.owner.is(Flags.Trait) ||
66+
(sym.isStatic && sym.is(Flags.Module, butNot = Flags.Method)))
67+
tree
6568
else {
6669
val isField = sym.owner.isClass
6770
if (isField) {

tests/run/i3634.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait T {
2+
case object Foo
3+
}
4+
5+
object Bar extends T
6+
7+
object Test {
8+
def main(args: Array[String]): Unit = {
9+
assert(Bar.Foo == Bar.Foo) // false
10+
}
11+
}

0 commit comments

Comments
 (0)