bug icon indicating copy to clipboard operation
bug copied to clipboard

Spec claims access modifier implies val

Open som-snytt opened this issue 3 years ago • 1 comments

Reproduction steps

Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.2).
Type in expressions for evaluation. Or try :help.

scala> class C(i: Int)
class C

scala> new C(42).i
                 ^
       error: value i is not a member of C

scala> object X { class C(private[X] i: Int) ; def x = new C(42).i }
                                                                 ^
       error: value i is not a member of X.C

scala> object X { class C(private[X] val i: Int) ; def x = new C(42).i }
object X

Problem

Spec claims

When access modifiers are given for a parameter, but no val or var keyword, val is assumed.

This came up recently on a forum or ticket, and I was confused by it again when looking at trait parameters on Scala 3.

Scala 3 gives the same result, so I assume the spec is wrong. Or maybe the spec is right and no one knows it.

som-snytt avatar Mar 21 '22 16:03 som-snytt

(Let's see what happens over in Scala 3 (at lampepfl/dotty#14735) before potentially making any changes to Scala 2.)

SethTisue avatar Apr 19 '22 17:04 SethTisue