Skip to content

Private class constructors should be ignored #738

Closed
@julienrf

Description

@julienrf

MiMa flags changes in private constructor signatures:

// v1.scala
case class Person private (name: String)

object Person:
  def apply(name: String): Person = new Person(name)
// v2.scala
case class Person private (name: String, address: Option[String])

object Person:
  def apply(name: String): Person = new Person(name, None)
  def apply(name: String, address: String): Person = new Person(name, Some(address))

Here, MiMa fails with a message like:

method this(java.lang.String)Unit in class Person does not have a correspondent in current version

However, the constructor is private, so the change is safe.

What happens is that although the constructor can’t be called from Scala code, it is effectively public in the bytecode (just like private[x] members).

MiMa should detect this pattern and ignore the changes to private class constructors.

Related discussions:

scala/bug#12711
scala/scala3#16651
scala/docs.scala-lang#2662
https://contributors.scala-lang.org/t/private-primary-constructor-vs-mima/6050

PR ignoring private[x] members: #583

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