File tree 3 files changed +59
-1
lines changed
compiler/src/dotty/tools/dotc
3 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,8 @@ class Compiler {
99
99
new ElimStaticThis , // Replace `this` references to static objects by global identifiers
100
100
new Flatten , // Lift all inner classes to package scope
101
101
new RestoreScopes ), // Repair scopes rendered invalid by moving definitions in prior phases of the group
102
- List (new MoveStatics , // Move static methods to companion classes
102
+ List (new TransformWildcards , // Replace wildcards with default values
103
+ new MoveStatics , // Move static methods to companion classes
103
104
new ExpandPrivate , // Widen private definitions accessed from nested classes
104
105
new SelectStatic , // get rid of selects that would be compiled into GetStatic
105
106
new CollectEntryPoints , // Find classes with main methods
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc
2
+ package transform
3
+
4
+ import TreeTransforms ._
5
+ import core .DenotTransformers ._
6
+ import core .Contexts ._
7
+ import ast .tpd
8
+
9
+ /** This phase transforms wildcards in valdefs with their default value.
10
+ * In particular for every valdef that is declared:
11
+ * `val x : T = _` to `val x : T = <zero of T>`
12
+ *
13
+ */
14
+ class TransformWildcards extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform =>
15
+ import tpd ._
16
+
17
+ override def phaseName = " transformWildcards"
18
+
19
+ override def checkPostCondition (tree : Tree )(implicit ctx : Context ): Unit = {
20
+ tree match {
21
+ case vDef : ValDef => assert(! tpd.isWildcardArg(vDef.rhs))
22
+ case _ =>
23
+ }
24
+ }
25
+
26
+ override def transformValDef (tree : ValDef )(implicit ctx : Context , info : TransformerInfo ): Tree = {
27
+ if (ctx.owner.isClass) tree
28
+ else cpy.ValDef (tree)(rhs = tree.rhs.wildcardToDefault)
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+
2
+ object Test {
3
+
4
+ class A {
5
+ private [this ] var x : String = _
6
+ }
7
+
8
+ class B {
9
+ private [this ] var x : String = _
10
+ x = " foo"
11
+ }
12
+
13
+ class C {
14
+ private [this ] var x1 : Int = _
15
+ private [this ] var x2 : Unit = _
16
+ private [this ] var x3 : Char = _
17
+ private [this ] var x4 : Boolean = _
18
+ private [this ] var x5 : Float = _
19
+ private [this ] var x6 : Double = _
20
+ private [this ] var x7 : Char = _
21
+ private [this ] var x8 : Byte = _
22
+ private [this ] var x9 : AnyVal = _
23
+ private [this ] var x10 : D = _
24
+ }
25
+
26
+ class D (x : Int ) extends AnyVal
27
+ }
You can’t perform that action at this time.
0 commit comments