Skip to content

Commit 2388ac7

Browse files
committed
Constructor proxy is protected if class is
1 parent 9066923 commit 2388ac7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ object NamerOps:
149149
*/
150150
def addConstructorApplies(scope: MutableScope, cls: ClassSymbol, modcls: ClassSymbol)(using Context): scope.type =
151151
def proxy(constr: Symbol): Symbol =
152+
var flags = ApplyProxyFlags | (constr.flagsUNSAFE & AccessFlags)
153+
if cls.is(Protected) then flags |= Protected
152154
newSymbol(
153155
modcls, nme.apply,
154-
ApplyProxyFlags | (constr.flagsUNSAFE & AccessFlags),
156+
flags,
155157
ApplyProxyCompleter(constr),
156158
cls.privateWithin,
157159
constr.coord)

tests/neg/i22560.scala

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
class A:
3+
protected class B
4+
5+
// This fails to compile, as expected
6+
val x = A().B() // error
7+
8+
object C:
9+
protected val p = "protected"
10+
protected def getString() = "Hello!"
11+
protected class D:
12+
def d = D() // ok
13+
14+
// This fails to compile
15+
// val y = C.p
16+
17+
// And this also fails to compile
18+
// val z = C.getString()
19+
20+
// However, this compiles just fine.
21+
val alpha = C.D() // error
22+
val beta = new C.D() // error

0 commit comments

Comments
 (0)