Skip to content

can't suppress / override synthetic companion .apply #9547

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

Closed
scabug opened this issue Nov 3, 2015 · 3 comments
Closed

can't suppress / override synthetic companion .apply #9547

scabug opened this issue Nov 3, 2015 · 3 comments

Comments

@scabug
Copy link

scabug commented Nov 3, 2015

I want a case class where the access to its constructors (including companion.apply) is private, or to not have the synthetic constructor created.

case class Foo private(x: Int)
object Foo {
  // apply not public
  def make(x: Int): Option[Foo] = ??? // public constructor
}

Adding or overriding Foo.apply causes "error: method apply is defined twice".

The only workaround I could find is to not use a case class; use a regular class, and define your own val, apply, unapply, toString, canEqual, equals, hashCode; seems unfortunate.

@scabug
Copy link
Author

scabug commented Nov 3, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9547?orig=1
Reporter: @refried
See #7884, #9425

@chrisandrews-ms
Copy link

Fixed in #10383?

@SethTisue
Copy link
Member

indeed!

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

No branches or pull requests

3 participants