Skip to content

Spec claims access modifier implies val #12562

Closed as not planned
Closed as not planned
@som-snytt

Description

@som-snytt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions