Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package-private nested case class in a library can be seen from other packages #18545

Closed
kubukoz opened this issue Sep 12, 2023 · 2 comments · Fixed by #18893
Closed

Package-private nested case class in a library can be seen from other packages #18545

kubukoz opened this issue Sep 12, 2023 · 2 comments · Fixed by #18893

Comments

@kubukoz
Copy link
Contributor

kubukoz commented Sep 12, 2023

Compiler version

3.3.1, 3.4.0-RC1-bin-20230911-1be790c-NIGHTLY

Minimized code

//> using scala "3.3.1"
//> using lib "org.typelevel::cats-effect:3.5.1"
import cats.effect.IOLocal
@main def demo = println(IOLocal.IOLocalImpl.apply(42))

Note: IOLocalImpl is defined as private[IOLocal] final class IOLocalImpl[A](default: A)

Output

cats.effect.IOLocal$IOLocalImpl@483bf400

Expectation

Compiler failure

Extra detail

I wasn't able to reproduce this without a library dependency.

@kubukoz kubukoz added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 12, 2023
@dwijnand
Copy link
Member

package iolib:
  case class IO[A](value: A)

  sealed trait IOLocal[A]

  object IOLocal:
    def apply[A](default: A): IO[IOLocal[A]] = IO(new IOLocalImpl(default))

    private[IOLocal] final class IOLocalImpl[A](default: A) extends IOLocal[A]

package tests:
  import iolib.IOLocal
  def test = IOLocal.IOLocalImpl.apply(42)

@dwijnand dwijnand added area:typer stat:needs triage Every issue needs to have an "area" and "itype" label and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 13, 2023
@som-snytt
Copy link
Contributor

Scala 2 also changes its messaging if the line is corrected:

package iolib {
  case class IO[A](value: A)

  sealed trait IOLocal[A]

  object IOLocal {
    def apply[A](default: A): IO[IOLocal[A]] = IO(new IOLocalImpl(default))

    private[IOLocal] final class IOLocalImpl[A](default: A) extends IOLocal[A]
  }
}

package tests {
  import iolib.IOLocal
  class C {
    def test = IOLocal.IOLocalImpl.apply(42)
    //def test = new IOLocal.IOLocalImpl(42)
  }
}

from

error: value IOLocalImpl is not a member of object iolib.IOLocal

to

error: class IOLocalImpl in object IOLocal cannot be accessed as a member of object iolib.IOLocal from class C in package tests

where Scala 3 misses the erroneous apply or constructor proxy.

odersky added a commit to dotty-staging/dotty that referenced this issue Nov 10, 2023
When creating a constructor proxy symbol we forgot to copy the
privateWithin of the traget class.

Fixes scala#18545
odersky added a commit that referenced this issue Nov 10, 2023
When creating a constructor proxy symbol we forgot to copy the
privateWithin of the target class.

Fixes #18545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants