Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private class constructors should be ignored #738

Closed
julienrf opened this issue Jan 13, 2023 · 4 comments
Closed

Private class constructors should be ignored #738

julienrf opened this issue Jan 13, 2023 · 4 comments

Comments

@julienrf
Copy link
Contributor

julienrf commented Jan 13, 2023

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

@jeroentervoorde
Copy link
Contributor

@SethTisue Could you take a look at my approach in #778 please?
Especially the bit on whether privateWithin constructors need to be ignored as well.

@julienrf
Copy link
Contributor Author

The issue is fixed by #778.

@mr-git
Copy link

mr-git commented Jun 17, 2024

was this released? I couldn't find if "ch.epfl.scala" % "sbt-version-policy" % "3.2.1" includes the fix for this

@SethTisue
Copy link
Collaborator

#778 hasn't appeared in a release yet. Thanks for bringing it up; we're overdue for a release. I've opened a ticket on it and assigned myself: #816

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants