Skip to content

Commit 4afa3ff

Browse files
committed
Revert "Fix ElimStaticThis#transformIdent"
This reverts commit 3d240ad. This commit got in without succeding the review. It broke what already was working(inner static objects), and made impossible moving static methods from companion object to companion class. Additionally, commenting or removing assertions is not the way to go, and should not pass review. See discussion here: dotty-staging@3d240ad
1 parent f078735 commit 4afa3ff

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ 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 Flatten,
7170
new ElimStaticThis,
71+
new Flatten,
7272
new RestoreScopes),
7373
List(/*new PrivateToStatic,*/
7474
new ExpandPrivate,

src/dotty/tools/dotc/transform/ElimStaticThis.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import dotty.tools.dotc.core.StdNames._
99
import dotty.tools.dotc.core.SymDenotations.SymDenotation
1010
import TreeTransforms.{MiniPhaseTransform, TransformerInfo}
1111
import dotty.tools.dotc.core.Types.{ThisType, TermRef}
12-
import Phases.Phase
1312

1413
/** Replace This references to module classes in static methods by global identifiers to the
1514
* corresponding modules.
@@ -18,8 +17,6 @@ class ElimStaticThis extends MiniPhaseTransform {
1817
import ast.tpd._
1918
def phaseName: String = "elimStaticThis"
2019

21-
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Flatten])
22-
2320
override def transformThis(tree: This)(implicit ctx: Context, info: TransformerInfo): Tree =
2421
if (!tree.symbol.is(Package) && ctx.owner.enclosingMethod.is(JavaStatic)) {
2522
assert(tree.symbol.is(ModuleClass))
@@ -28,12 +25,10 @@ class ElimStaticThis extends MiniPhaseTransform {
2825
else tree
2926

3027
override def transformIdent(tree: tpd.Ident)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
31-
val meth = ctx.owner.enclosingMethod
32-
// We cannot use meth.enclosingClass because it skips other static classes,
33-
// so instead we require this phase to run after Flatten and use meth.owner
34-
if (meth.is(JavaStatic) && meth.owner.is(ModuleClass)) {
28+
if (ctx.owner.enclosingMethod.is(JavaStatic)) {
3529
tree.tpe match {
36-
case TermRef(thiz: ThisType, _) if (thiz.underlying.typeSymbol == meth.owner) =>
30+
case TermRef(thiz: ThisType, _) =>
31+
assert(thiz.underlying.typeSymbol.is(ModuleClass))
3732
ref(thiz.underlying.typeSymbol.sourceModule).select(tree.symbol)
3833
case _ => tree
3934
}

0 commit comments

Comments
 (0)