File tree Expand file tree Collapse file tree 8 files changed +69
-29
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 8 files changed +69
-29
lines changed Original file line number Diff line number Diff line change @@ -61,9 +61,9 @@ class Compiler {
61
61
List (new FirstTransform , // Some transformations to put trees into a canonical form
62
62
new CheckReentrant , // Internal use only: Check that compiled program has no data races involving global vars
63
63
new ElimPackagePrefixes ) :: // Eliminate references to package prefixes in Select nodes
64
- List (new CheckStatic , // Check restrictions that apply to @static members
64
+ List (new ElimLocals , // Widens private[this] and protected[this] modifiers to just private/protected
65
+ new CheckStatic , // Check restrictions that apply to @static members
65
66
new ElimRepeated , // Rewrite vararg parameters and arguments
66
- new NormalizeFlags , // Rewrite some definition flags
67
67
new ExpandSAMs , // Expand single abstract method closures to anonymous classes
68
68
new ProtectedAccessors , // Add accessors for protected members
69
69
new ExtensionMethods , // Expand methods of value classes with extension methods
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc
2
+ package transform
3
+
4
+ import core ._
5
+ import DenotTransformers .SymTransformer
6
+ import Phases .Phase
7
+ import Contexts .Context
8
+ import SymDenotations .SymDenotation
9
+ import MegaPhase .MiniPhase
10
+ import Flags ._ , Symbols ._
11
+ import SymUtils ._
12
+
13
+ /** This phase drops the Local flag from all private[this] and protected[this] members.
14
+ *
15
+ * This allows subsequent code motions where code is moved from a class to its
16
+ * companion object.
17
+ * We maintain the Local flag for field since then cannot move to the companion
18
+ * object and it is used in later Getter.
19
+ */
20
+ class ElimLocals extends MiniPhase with SymTransformer {
21
+ override def phaseName = ElimLocals .name
22
+
23
+ def transformSym (ref : SymDenotation )(implicit ctx : Context ) =
24
+ if (ref.is(Local ) && ! ref.isField) ref.copySymDenotation(initFlags = ref.flags &~ Local )
25
+ else ref
26
+ }
27
+
28
+ object ElimLocals {
29
+ def name = " elimlocals"
30
+ }
Original file line number Diff line number Diff line change @@ -47,7 +47,9 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
47
47
48
48
override def runsAfter = Set (
49
49
ElimRepeated .name,
50
- ProtectedAccessors .name // protected accessors cannot handle code that is moved from class to companion object
50
+ ProtectedAccessors .name, // protected accessors cannot handle code that is moved from class to companion object
51
+ ElimLocals .name // private[this] accessors need to be widened before
52
+ // a methods is moved to its companion object
51
53
)
52
54
53
55
override def runsAfterGroupsOf = Set (FirstTransform .name) // need companion objects to exist
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ class Flatten extends MiniPhase with SymTransformer {
17
17
18
18
override def phaseName = " flatten"
19
19
20
+ // private[this] modifiers on classes need be widened before lifting the class
21
+ override def runsAfter = Set (ElimLocals .name)
22
+
20
23
override def changesMembers = true // the phase removes inner classes
21
24
22
25
private var LiftedDefs : Store .Location [mutable.ListBuffer [Tree ]] = _
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ class Getters extends MiniPhase with SymTransformer {
54
54
override def transformSym (d : SymDenotation )(implicit ctx : Context ): SymDenotation = {
55
55
def noGetterNeeded =
56
56
d.is(NoGetterNeeded ) ||
57
- d.initial. asInstanceOf [ SymDenotation ]. is(PrivateLocal ) && ! d.owner.is(Trait ) && ! isDerivedValueClass(d.owner) && ! d.is(Flags .Lazy ) ||
57
+ d.is(PrivateLocal ) && ! d.owner.is(Trait ) && ! isDerivedValueClass(d.owner) && ! d.is(Flags .Lazy ) ||
58
58
d.is(Module ) && d.isStatic ||
59
59
d.hasAnnotation(defn.ScalaStaticAnnot ) ||
60
60
d.isSelfSym
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ object A1 {
2
+ private [this ] class B
3
+
4
+ private [this ] class C {
5
+ def cons : B = new B
6
+ }
7
+ }
8
+
9
+ class A2 {
10
+ private [this ] class B
11
+
12
+ private [this ] class C {
13
+ def cons : B = new B
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ class StringOps (val s : String ) extends AnyVal {
2
+ def lines : Iterator [String ] = new collection.AbstractIterator [String ] {
3
+ private [this ] var index = 0
4
+ def hasNext : Boolean = false
5
+ def next (): String = {
6
+ index = 1
7
+ " "
8
+ }
9
+ }
10
+ }
11
+
12
+ class FooOps (val s : String ) extends AnyVal {
13
+ private [this ] def bar = 2
14
+ def foo = bar
15
+ }
You can’t perform that action at this time.
0 commit comments