Skip to content

Commit 22063fa

Browse files
authored
Also add privateWithin when creating constructor proxies (#18893)
When creating a constructor proxy symbol we forgot to copy the privateWithin of the target class. Fixes #18545
2 parents 6b12bf0 + 38860c8 commit 22063fa

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

compiler/src/dotty/tools/dotc/core/NamerOps.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ object NamerOps:
111111
def addConstructorApplies(scope: MutableScope, cls: ClassSymbol, modcls: ClassSymbol)(using Context): scope.type =
112112
def proxy(constr: Symbol): Symbol =
113113
newSymbol(
114-
modcls, nme.apply, ApplyProxyFlags | (constr.flagsUNSAFE & AccessFlags),
115-
ApplyProxyCompleter(constr), coord = constr.coord)
114+
modcls, nme.apply,
115+
ApplyProxyFlags | (constr.flagsUNSAFE & AccessFlags),
116+
ApplyProxyCompleter(constr),
117+
cls.privateWithin,
118+
constr.coord)
116119
for dcl <- cls.info.decls do
117120
if dcl.isConstructor then scope.enter(proxy(dcl))
118121
scope

tests/neg/i18545.check

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- [E173] Reference Error: tests/neg/i18545.scala:13:20 ----------------------------------------------------------------
2+
13 | def test: IOLocal.IOLocalImpl[Int] = // error
3+
| ^^^^^^^^^^^^^^^^^^^
4+
|class IOLocalImpl cannot be accessed as a member of iolib.IOLocal.type from the top-level definitions in package tests.
5+
| private[IOLocal] class IOLocalImpl can only be accessed from object IOLocal in package iolib.
6+
-- [E173] Reference Error: tests/neg/i18545.scala:14:24 ----------------------------------------------------------------
7+
14 | IOLocal.IOLocalImpl.apply(42) // error
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
9+
|method apply cannot be accessed as a member of iolib.IOLocal.IOLocalImpl.type from the top-level definitions in package tests.
10+
| private[IOLocal] method apply can only be accessed from object IOLocal in package iolib.
11+
-- [E050] Type Error: tests/neg/i18545.scala:15:22 ---------------------------------------------------------------------
12+
15 | def test2 = IOLocal.IOLocalImpl(42) // error
13+
| ^^^^^^^^^^^^^^^^^^^
14+
| object IOLocalImpl in object IOLocal does not take parameters
15+
|
16+
| longer explanation available when compiling with `-explain`

tests/neg/i18545.scala

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package iolib:
2+
case class IO[A](value: A)
3+
4+
sealed trait IOLocal[A]
5+
6+
object IOLocal:
7+
def apply[A](default: A): IO[IOLocal[A]] = IO(new IOLocalImpl(default))
8+
9+
private[IOLocal] final class IOLocalImpl[A](default: A) extends IOLocal[A]
10+
11+
package tests:
12+
import iolib.IOLocal
13+
def test: IOLocal.IOLocalImpl[Int] = // error
14+
IOLocal.IOLocalImpl.apply(42) // error
15+
def test2 = IOLocal.IOLocalImpl(42) // error

0 commit comments

Comments
 (0)