Skip to content

Commit

Permalink
Also add privateWithin when creating constructor proxies (#18893)
Browse files Browse the repository at this point in the history
When creating a constructor proxy symbol we forgot to copy the
privateWithin of the target class.

Fixes #18545
  • Loading branch information
odersky authored Nov 10, 2023
2 parents 6b12bf0 + 38860c8 commit 22063fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
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

0 comments on commit 22063fa

Please sign in to comment.