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 constructors of case class defined in method body should not be accessible outside of the class/object definitions #8821

Closed
scabug opened this issue Aug 25, 2014 · 4 comments
Milestone

Comments

@scabug
Copy link

scabug commented Aug 25, 2014

A private constructor of case class is only accessible in the class/companion object definition. Trying to access from anywhere else results a compilation error.

// CodeInBody.scala
object CodeInBody {
  case class A private (i: Int)
  val a1 = A(1)    // compilation error
}

Except if the case class is defined in a method body.

// CodeInMethod.scala
object CodeInMethod {
  def f {
    case class A private (i: Int)
    val a1 = A(1)   // no compilation error
  }
}

I would expect the same behavior in both cases.

@scabug
Copy link
Author

scabug commented Aug 25, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8821?orig=1
Reporter: @skyluc
Affected Versions: 2.11.2

@scabug
Copy link
Author

scabug commented Aug 25, 2014

@scabug
Copy link
Author

scabug commented Jul 31, 2015

@jsuereth said:
I think I ran into an instance of this recently with combined vs. separate compilation: https://gist.github.com/jsuereth/bf94458a0d03035b58c3

@scabug
Copy link
Author

scabug commented Jun 29, 2016

@som-snytt said:
The related fix makes the behavior uniform.

The equivocation about the apply and the ctor is common parlance:

http://stackoverflow.com/questions/38097490/scala-case-class-private-constructor-isnt-private

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