Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
class OffsetInfo(var defs: List[Tree], var ord:Int)
val appendOffsetDefs = mutable.Map.empty[Symbol, OffsetInfo]

override def phaseName: String = "LazyVals"
override def phaseName: String = "lazyVals"

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

def transformLazyVal(tree: ValOrDefDef)(implicit ctx: Context): Tree = {
val sym = tree.symbol
if (!(sym is Flags.Lazy) || sym.owner.is(Flags.Trait) || (sym.isStatic && sym.is(Flags.Module))) tree
if (!(sym is Flags.Lazy) ||
sym.owner.is(Flags.Trait) ||
(sym.isStatic && sym.is(Flags.Module, butNot = Flags.Method)))
tree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment here explaining why this is OK in these cases?

else {
val isField = sym.owner.isClass
if (isField) {
Expand Down
11 changes: 11 additions & 0 deletions tests/run/i3634.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait T {
case object Foo
}

object Bar extends T

object Test {
def main(args: Array[String]): Unit = {
assert(Bar.Foo == Bar.Foo) // false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use eq instead of == to be extra sure that nothing funny is going on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a object Baz extends T and assert(Bar.Foo ne Baz.Foo)

}
}