Skip to content

Private constructor pollute visibility of methods #6671

Closed
@andreaTP

Description

@andreaTP

Using a private constructor with case classes cause other methods to be considered private.

Repro 1:

case class X3 private (foo: Int)
val x = X3(1)

trigger:

constructor X3 cannot be accessed as a member of X3

Repro 2:

object X2 {
  def apply(
    foo: Int,
    bar: String = ""
  ) = new X2(foo, bar)
}

case class X2 private (
  foo: Int,
  bar: String = ""
)

val x = X2(1)
x.copy(1, "2")

trigger:

method copy in class X2 cannot be accessed as a member of X2

Both examples compiles with scalac 2.12 because only the canonical constructor is affected by the restriction of visibility.
i.e. both the apply in the companion object and the copy method should be accessible.

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