Skip to content

Commit 11fbe4e

Browse files
committed
Constructor companion gets privateWithin
1 parent 345b2da commit 11fbe4e

File tree

7 files changed

+78
-2
lines changed

7 files changed

+78
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ object NamerOps:
183183
cls.owner, cls.name.toTermName,
184184
flags, flags,
185185
constructorCompanionCompleter(cls),
186-
coord = cls.coord,
187-
compUnitInfo = cls.compUnitInfo)
186+
cls.privateWithin,
187+
cls.coord,
188+
cls.compUnitInfo)
188189
companion.moduleClass.registerCompanion(cls)
189190
cls.registerCompanion(companion.moduleClass)
190191
companion

tests/neg/i22560b.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ package p:
1212
private[p] class C(i: Int) // ctor proxy gets privateWithin of class
1313
private[p] class D(i: Int)
1414
object D
15+
private class E(i: Int)
1516

1617
package q:
1718
def f() = p.C(42) // error
1819
def g() = p.D(42) // error
20+
def h() = p.E(42) // error

tests/neg/i22560c/client_2.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
package i22560:
3+
val alpha = C.D() // error
4+
5+
class Test extends Enumeration:
6+
val Hearts = Val(27) // error
7+
val Diamonds = Val() // error
8+
9+
package q:
10+
def f() = p.C(42) // error
11+
def g() = p.D(42) // error

tests/neg/i22560c/lib_1.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
package i22560:
3+
4+
object C:
5+
protected class D
6+
7+
class Enumeration:
8+
protected class Val(i: Int):
9+
def this() = this(42)
10+
object Val
11+
12+
package p:
13+
private[p] class C(i: Int) // companion gets privateWithin of class
14+
private[p] class D(i: Int) // ctor proxy gets privateWithin of class
15+
object D
16+

tests/pos/i22560.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ package companioned:
2020
class Test extends Enumeration:
2121
val Hearts = Val(27)
2222
val Diamonds = Val()
23+
24+
package p:
25+
26+
package internal:
27+
28+
protected[p] class P(i : Int)
29+
private[p] class Q(i : Int)
30+
31+
def f = internal.P(42)
32+
def g = internal.Q(42)

tests/pos/i22560b/client_2.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
package companionless:
3+
4+
class Test extends Enumeration:
5+
val Hearts = Val(27)
6+
val Diamonds = Val()
7+
8+
9+
package companioned:
10+
11+
class Test extends Enumeration:
12+
val Hearts = Val(27)
13+
val Diamonds = Val()
14+
15+
package p:
16+
17+
def f = internal.P(42)

tests/pos/i22560b/lib_1.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
package companionless:
3+
4+
class Enumeration:
5+
protected class Val(i: Int):
6+
def this() = this(42)
7+
8+
package companioned:
9+
10+
class Enumeration:
11+
protected class Val(i: Int):
12+
def this() = this(42)
13+
protected object Val
14+
15+
package p:
16+
17+
package internal:
18+
19+
protected[p] class P(i : Int)

0 commit comments

Comments
 (0)