AnyVal makes private case class constructor public

77 views
Skip to first unread message

Philippe Suter

unread,
Apr 5, 2016, 2:14:51 PM4/5/16
to scala-language
I'm wondering if the observed behavior is intentional; in the attached file, I expect the three class construction calls to fail, but only the ones commented out do.

It seems that having a case class extends AnyVal renders its constructor public.

Maybe a special case of https://github.com/scala/scala/pull/2236 ?

Tested on Scala 2.11.8.

Best regards,
PS
Example.scala

som-snytt

unread,
Apr 14, 2016, 5:10:17 PM4/14/16
to scala-language

Gitter seems to have made the lists moribund.

I don't see the behavior you report. Related https://issues.scala-lang.org/browse/SI-9425

$ scala
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions for evaluation. Or try :help.

scala> :pa
// Entering paste mode (ctrl-D to finish)

case class C private(i: Int)

C(42).i

// Exiting paste mode, now interpreting.

defined class C
res0: Int = 42

scala> :pa
// Entering paste mode (ctrl-D to finish)

case class C private(i: Int) extends AnyVal

C(42).i

// Exiting paste mode, now interpreting.

defined class C
res1: Int = 42

scala>

Reply all
Reply to author
Forward
0 new messages