Skip to content

Fix #3624: Lazily evaluate static module accessors #3719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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) || // val is accessor, lazy field will be implemented in subclass
(sym.isStatic && sym.is(Flags.Module, butNot = Flags.Method))) // static module vals are implemented in the JVM by lazy loading
tree
else {
val isField = sym.owner.isClass
if (isField) {
Expand Down
7 changes: 7 additions & 0 deletions tests/pending/run/implicits-numeric.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test extends App {

implicit def _1: Long = 1L
implicit def _2: Int = 0

println(implicitly[AnyVal])
}
13 changes: 13 additions & 0 deletions tests/run/i3624.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
trait T {
case object Foo
}

object Bar extends T
object Baz extends T

object Test {
def main(args: Array[String]): Unit = {
assert(Bar.Foo eq Bar.Foo)
assert(Bar.Foo ne Baz.Foo)
}
}