Skip to content

Commit b6ad24f

Browse files
committed
Reference on access of ctor proxy
1 parent fddab10 commit b6ad24f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/_docs/reference/other-new-features/creator-applications.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ The precise rules are as follows:
3939
- the class has a companion object (which might have been generated in step 1), and
4040
- that companion object does not already define a member named `apply`.
4141

42-
Each generated `apply` method forwards to one constructor of the class. It has the
43-
same type and value parameters as the constructor.
42+
Each generated `apply` method forwards to one constructor of the class.
43+
It has the same type and value parameters as the constructor,
44+
as well as the same access restriction as the class.
45+
If the class is `protected`, then either the companion object must be `protected`
46+
or the `apply` method will be made `protected`.
4447

4548
Constructor proxy companions cannot be used as values by themselves. A proxy companion object must
4649
be selected with `apply` (or be applied to arguments, in which case the `apply` is implicitly

tests/neg/i22560b.scala

+9
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ class Enumeration:
77
class Test extends Enumeration:
88
val Hearts = Val(27) // error
99
val Diamonds = Val() // error
10+
11+
package p:
12+
private[p] class C(i: Int) // ctor proxy gets privateWithin of class
13+
private[p] class D(i: Int)
14+
object D
15+
16+
package q:
17+
def f() = p.C(42) // error
18+
def g() = p.D(42) // error

0 commit comments

Comments
 (0)