File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ class Compiler {
67
67
new Constructors ,
68
68
new FunctionalInterfaces ),
69
69
List (new LambdaLift , // in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
70
+ new ElimStaticThis ,
70
71
new Flatten ,
71
72
new RestoreScopes ),
72
73
List (/* new PrivateToStatic,*/
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc
2
+ package transform
3
+
4
+ import core ._
5
+ import Contexts .Context
6
+ import Flags ._
7
+ import dotty .tools .dotc .ast .tpd
8
+ import dotty .tools .dotc .core .StdNames ._
9
+ import dotty .tools .dotc .core .SymDenotations .SymDenotation
10
+ import TreeTransforms .{MiniPhaseTransform , TransformerInfo }
11
+ import dotty .tools .dotc .core .Types .{ThisType , TermRef }
12
+
13
+ /** Replace This references to module classes in static methods by global identifiers to the
14
+ * corresponding modules.
15
+ */
16
+ class ElimStaticThis extends MiniPhaseTransform {
17
+ import ast .tpd ._
18
+ def phaseName : String = " elimStaticThis"
19
+
20
+ override def transformThis (tree : This )(implicit ctx : Context , info : TransformerInfo ): Tree =
21
+ if (! tree.symbol.is(Package ) && ctx.owner.enclosingMethod.is(JavaStatic )) {
22
+ assert(tree.symbol.is(ModuleClass ))
23
+ ref(tree.symbol.sourceModule)
24
+ }
25
+ else tree
26
+
27
+ override def transformIdent (tree : tpd.Ident )(implicit ctx : Context , info : TransformerInfo ): tpd.Tree = {
28
+ if (ctx.owner.enclosingMethod.is(JavaStatic )) {
29
+ tree.tpe match {
30
+ case TermRef (thiz : ThisType , _) =>
31
+ assert(thiz.underlying.typeSymbol.is(ModuleClass ))
32
+ ref(thiz.underlying.typeSymbol.sourceModule).select(tree.symbol)
33
+ case _ => tree
34
+ }
35
+ }
36
+ else tree
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments