Skip to content

Dotty initialization deviates from Scalac and lang spec #7434

Closed
@liufengyun

Description

@liufengyun

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions