You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you try to uncomment object MyClass1 you will gen compilation error:
object MyClass1 { def apply(): MyClass1 = new MyClass1() }
private class MyClass1 escapes its defining scope as part of type org.aaa.bbb.MyClass1
object MyClass1 { def apply(): MyClass1 = new MyClass1() }
It's understandable...
private[bbb] should be the same as private,
But compiler generates no error for object MyClass2
Thus you can use any MyClass2 public methods via calling companion object apply method MyClass2().foo from any package
The text was updated successfully, but these errors were encountered:
I'm pretty sure this backdoor access has always been true; I remember being surprised by it.
The closest ticket I find for linking is #11339 ("qualified private/protected have no chance whatsoever of ever working correctly") from 2017 or #5008 ("There are so many access related tickets open I can't tell in a reasonable amount of time if this already exists." "Overtaken by events." "Nifty.") from 2011.
The canonical ticket #6794 mentions #1800 which is still open.
The question whether private is "the same" as private[pkg] is interesting to debate over qualifying beverages. (Edit: it's not the same, spoiler alert.)
(original question: https://gitter.im/scala/scala?at=5f4510cb59ac794e02c5aaa9)
reproduction steps
using Scala (2.12.10, 2.13.3),
problem
If you try to uncomment
object MyClass1
you will gen compilation error:It's understandable...
private[bbb]
should be the same asprivate
,But compiler generates no error for
object MyClass2
Thus you can use any
MyClass2
public methods via calling companion objectapply
methodMyClass2().foo
from any packageThe text was updated successfully, but these errors were encountered: