Skip to content

Classes can't have unit fields? #8036

Closed
@travisbrown

Description

@travisbrown

minimized code

class UnitClass(val x: Unit)

object Test {
  def main(args: Array[String]): Unit = {
    println(new UnitClass(()))
  }
}
Compiles but fails at runtime
Exception in thread "main" java.lang.NoSuchFieldError: UnitClass.x
	at UnitClass.<init>(Test.scala:1)
	at Test$.main(Test.scala:5)
	at Test.main(Test.scala)

expectation

It works fine on Scala 2. It also works fine if you change the Unit to e.g. Int or String.

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