Skip to content

Also add privateWithin when creating constructor proxies #18893

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

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/NamerOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ object NamerOps:
def addConstructorApplies(scope: MutableScope, cls: ClassSymbol, modcls: ClassSymbol)(using Context): scope.type =
def proxy(constr: Symbol): Symbol =
newSymbol(
modcls, nme.apply, ApplyProxyFlags | (constr.flagsUNSAFE & AccessFlags),
ApplyProxyCompleter(constr), coord = constr.coord)
modcls, nme.apply,
ApplyProxyFlags | (constr.flagsUNSAFE & AccessFlags),
ApplyProxyCompleter(constr),
cls.privateWithin,
constr.coord)
for dcl <- cls.info.decls do
if dcl.isConstructor then scope.enter(proxy(dcl))
scope
Expand Down
16 changes: 16 additions & 0 deletions tests/neg/i18545.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- [E173] Reference Error: tests/neg/i18545.scala:13:20 ----------------------------------------------------------------
13 | def test: IOLocal.IOLocalImpl[Int] = // error
| ^^^^^^^^^^^^^^^^^^^
|class IOLocalImpl cannot be accessed as a member of iolib.IOLocal.type from the top-level definitions in package tests.
| private[IOLocal] class IOLocalImpl can only be accessed from object IOLocal in package iolib.
-- [E173] Reference Error: tests/neg/i18545.scala:14:24 ----------------------------------------------------------------
14 | IOLocal.IOLocalImpl.apply(42) // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|method apply cannot be accessed as a member of iolib.IOLocal.IOLocalImpl.type from the top-level definitions in package tests.
| private[IOLocal] method apply can only be accessed from object IOLocal in package iolib.
-- [E050] Type Error: tests/neg/i18545.scala:15:22 ---------------------------------------------------------------------
15 | def test2 = IOLocal.IOLocalImpl(42) // error
| ^^^^^^^^^^^^^^^^^^^
| object IOLocalImpl in object IOLocal does not take parameters
|
| longer explanation available when compiling with `-explain`
15 changes: 15 additions & 0 deletions tests/neg/i18545.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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[Int] = // error
IOLocal.IOLocalImpl.apply(42) // error
def test2 = IOLocal.IOLocalImpl(42) // error