Skip to content

Commit 65ca99d

Browse files
authored
Clarify reference on inferred object-private parameter (#22621)
Document the status quo. Documents #22620
2 parents 705e10e + 7aca128 commit 65ca99d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Diff for: docs/_docs/reference/dropped-features/this-qualifier.md

+12
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@ This can cause problems if a program tries to access the missing private field v
2929
// [C] needed if `field` is to be accessed through reflection
3030
val retained = field * field
3131
```
32+
33+
Class parameters are normally inferred object-private,
34+
so that members introduced by explicitly declaring them `val` or `var` are exempt from the rule described here.
35+
36+
In particular, the following field is not excluded from variance checking:
37+
```scala
38+
class C[-T](private val t: T) // error
39+
```
40+
And in contrast to the private field shown above, this field is not eliminated:
41+
```scala
42+
class C(private val c: Int)
43+
```

Diff for: tests/neg/i22620.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
import scala.collection.mutable.ArrayBuffer
3+
4+
class PrivateTest[-M](private val v: ArrayBuffer[M]) // error

0 commit comments

Comments
 (0)