Skip to content

Commit aa7ac11

Browse files
committed
Deprecate private[this] and protected[this] in 3.1
Add docs to state that they will be dropped.
1 parent 6098418 commit aa7ac11

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,11 @@ object Parsers {
26422642
if (mods.is(Local) || mods.hasPrivateWithin)
26432643
syntaxError(DuplicatePrivateProtectedQualifier())
26442644
inBrackets {
2645-
if (in.token == THIS) { in.nextToken(); mods | Local }
2645+
if in.token == THIS then
2646+
if ctx.settings.strict.value then
2647+
deprecationWarning("The [this] qualifier is deprecated in Scala 3.1; it should be dropped.")
2648+
in.nextToken()
2649+
mods | Local
26462650
else mods.withPrivateWithin(ident().toTypeName)
26472651
}
26482652
}

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ LocalModifier ::= ‘abstract’
331331
| ‘lazy’
332332
| ‘inline’
333333
AccessModifier ::= (‘private’ | ‘protected’) [AccessQualifier]
334-
AccessQualifier ::= ‘[’ (id | ‘this’) ‘]’
334+
AccessQualifier ::= ‘[’ id ‘]’
335335
336336
Annotation ::= ‘@’ SimpleType {ParArgumentExprs} Apply(tpe, args)
337337
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: doc-page
3+
title: Dropped: private[this] and protected[this]
4+
---
5+
6+
The `private[this]` and `protected[this]` access modifiers are deprecated and will be phased out.
7+
8+
Previously, these modifier were needed
9+
10+
- for avoiding the generation of getters and setters
11+
- for excluding code under a `private[this]` from variance checks. (Scala 2 also excludes `protected[this]` but this was found to be unsound and was therefore removed).
12+
13+
The compiler now infers for `private` members the fact that they are only accessed via `this`. Such members are treated as if they had been declared `private[this]`. `protected[this]` is dropped without a replacement.
14+

docs/sidebar.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ sidebar:
171171
url: docs/reference/dropped-features/weak-conformance.html
172172
- title: Nonlocal Returns
173173
url: docs/reference/dropped-features/nonlocal-returns.html
174+
- title: `[this]` Qualifier
175+
url: docs/reference/dropped-features/this-qualifier.html
174176
- title: Contributing
175177
subsection:
176178
- title: Contribute Knowledge

0 commit comments

Comments
 (0)