Skip to content

Dotty initialization deviates from Scalac and lang spec #7434

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

Closed
liufengyun opened this issue Oct 17, 2019 · 0 comments
Closed

Dotty initialization deviates from Scalac and lang spec #7434

liufengyun opened this issue Oct 17, 2019 · 0 comments

Comments

@liufengyun
Copy link
Contributor

liufengyun commented Oct 17, 2019

A bug discovered by initialization checker:

minimized code

// tests/pos/t704.scala
trait D {
  private val x = "xxxx should appear twice"
  private object xxxx { Console.println(x) }
  def get_xxxx: AnyRef = xxxx
}

trait E extends D {
  def f(): Unit = {
    val y = "yyyy should appear twice"
    object yyyy {
      val x1 = get_xxxx
      Console.println(y)
    }
    yyyy
  }
}
class C extends E {}
object Go extends D {
  def main(args : Array[String]): Unit = {
    new C().f()
    new C().f()
  }
}

Compile and run the code with Dotty, it prints:

null
null
yyyy should appear twice
null
yyyy should appear twice

Scala 2.12 and 2.13 prints:

xxxx should appear twice
yyyy should appear twice
xxxx should appear twice
yyyy should appear twice

expectation

Dotty should print the same as Scalac, which is in accord with language spec.

odersky added a commit that referenced this issue Oct 26, 2019
Fix #7434: Tighten a condition in LazyVals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant