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

Scalac ignores private constructor for value class from classpath #6601

Closed
scabug opened this issue Nov 1, 2012 · 6 comments
Closed

Scalac ignores private constructor for value class from classpath #6601

scabug opened this issue Nov 1, 2012 · 6 comments

Comments

@scabug
Copy link

@scabug scabug commented Nov 1, 2012

  1. Create PrivateConstructor.scala:
class PrivateConstructor private(val s: String) extends AnyVal
  1. Run scalac:
scalac PrivateConstructor.scala
  1. Create AccessPrivateConstructor.scala:
class AccessPrivateConstructor {
  new PrivateConstructor("") // Scalac should forbid accessing to the private constructor!
}
  1. Run scalac:
scalac AccessPrivateConstructor.scala

I expect scalac to print some compilation error, but scalac does not print any thing. Scalac just ignores the private modifier for constructor when parsing PrivateConstructor.class.

@scabug
Copy link
Author

@scabug scabug commented Nov 1, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6601?orig=1
Reporter: @Atry
Affected Versions: 2.10.0-RC1

@scabug
Copy link
Author

@scabug scabug commented Jan 16, 2013

@retronym said:
Seems to be leftover from scala/scala@437c626

extmethods sets notPRIVATE on the primary constructor, but it runs before pickler.

@scabug
Copy link
Author

@scabug scabug commented Jan 16, 2013

@scabug
Copy link
Author

@scabug scabug commented Jan 26, 2013

@retronym said:
Reopening: the remedy was far worse than the disease:

  ~/code/scala cat sandbox/test.scala 
class V private (val a: Any) extends AnyVal
  ~/code/scala RUNNER=scalac scala-hash b07228aebe sandbox/test.scala 
[info] b07228aebe => /Users/jason/usr/scala-v2.10.0-256-gb07228a
  ~/code/scala scala-hash b07228aebe 
[info] b07228aebe => /Users/jason/usr/scala-v2.10.0-256-gb07228a
Welcome to Scala version 2.10.1-20130116-230935-b07228aebe (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
Type in expressions to have them evaluated.
Type :help for more information.

scala> def foo(v: V) = v.a == v.a
exception when typing v.a().==(v.a())/class scala.reflect.internal.Trees$Apply
constructor V in class V cannot be accessed in object $iw in file <console>
scala.reflect.internal.Types$TypeError: constructor V in class V cannot be accessed in object $iw

@scabug
Copy link
Author

@scabug scabug commented Mar 11, 2013

@scabug
Copy link
Author

@scabug scabug commented Mar 11, 2013

@retronym said:
We can't fix this in the 2.10.x series as we need an incompatible change of the pickled flags.

I've submitted a PR to do that for 2.11.0-M3:

scala/scala#2236

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

Successfully merging a pull request may close this issue.

None yet
2 participants