Skip to content

Value class equality boxes #9413

Closed
Closed
@odersky

Description

@odersky

Minimized example

Compile the following with -Xprint:elimErasedValueType

class ApproxState(private val bits: Int) extends AnyVal

object Main {
  val FreshApprox: ApproxState = new ApproxState(4)
  var approx: ApproxState = FreshApprox
  println(approx == FreshApprox)
}

Output

The last statement compiles to:

    println(
      scala.Boolean.box(
        new ApproxState(Main.approx()).==(new ApproxState(Main.FreshApprox()))
      )
    )

Expectation

No boxing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions