Skip to content

Commit db11fc5

Browse files
committed
New phase ElimStaticThis
1 parent 878b55a commit db11fc5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Compiler {
6767
new Constructors,
6868
new FunctionalInterfaces),
6969
List(new LambdaLift, // in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
70+
new ElimStaticThis,
7071
new Flatten,
7172
new RestoreScopes),
7273
List(/*new PrivateToStatic,*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dotty.tools.dotc
2+
package transform
3+
4+
import core._
5+
import Contexts.Context
6+
import Flags._
7+
import dotty.tools.dotc.core.StdNames._
8+
import dotty.tools.dotc.core.SymDenotations.SymDenotation
9+
import TreeTransforms.{MiniPhaseTransform, TransformerInfo}
10+
11+
/** Replace This references to module classes in static methods by global identifiers to the
12+
* corresponding modules.
13+
*/
14+
class ElimStaticThis extends MiniPhaseTransform {
15+
import ast.tpd._
16+
def phaseName: String = "elimStaticThis"
17+
18+
override def transformThis(tree: This)(implicit ctx: Context, info: TransformerInfo): Tree =
19+
if (!tree.symbol.is(Package) && ctx.owner.enclosingMethod.is(JavaStatic)) {
20+
assert(tree.symbol.is(ModuleClass))
21+
ref(tree.symbol.sourceModule)
22+
}
23+
else tree
24+
}

0 commit comments

Comments
 (0)