Skip to content

Initialization of nested objects differs based on whether they are wrapped in a trait #21444

Open
@lihaoyi

Description

@lihaoyi

Compiler version

3.5.0, same behavior in 2.13.14

Minimized code

The following code does not print Hello outer

object outer{
  println("Hello outer")
  object Foo
}
object Test{
  def main(args: Array[String]): Unit = println("Hello " + outer.Foo)
}

But if I wrap the object outer in a trait, it does print Hello outer

trait wrapper{
  object outer{
    println("Hello outer")
    object Foo
  }
}
object Test{
  def main(args: Array[String]): Unit = {
    println("Hello " + new wrapper{}.outer.Foo)
  }
}

Expectation

I would expect the initialization behavior of nested objects to be consistent regardless of whether or not they are wrapped in traits

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions