Skip to content

Erasure removes Unit typed local lazy val references #5350

Closed
@allanrenucci

Description

@allanrenucci
scala> def foo = { lazy val bar: Unit = { println("Hello") }; bar }
def foo: Unit

scala> bar
// nothing happen

Given:

class Test {
  def foo = {
    lazy val bar: Unit = println("Hello")
    bar
  }
}

After erasure:

class Test() {
  def foo(): Unit = {
    lazy <accessor> def bar(): scala.runtime.BoxedUnit = {
      println("Hello")
      scala.runtime.BoxedUnit$#UNIT
    }
    () // no more call to `bar`
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions