-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3917: Properly desugar Ident
#3925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import core.Symbols._ | |
import core.Types._ | ||
import typer.ConstFold | ||
import ast.Trees._ | ||
import Simplify.desugarIdent | ||
|
||
/** Various constant folding. | ||
* | ||
|
@@ -182,22 +181,19 @@ import Simplify.desugarIdent | |
case _ => false | ||
} | ||
case t1: Ident => | ||
desugarIdent(t1) match { | ||
case Some(t) => | ||
val t2i = t2 match { | ||
case t2: Ident => desugarIdent(t2).getOrElse(t2) | ||
case _ => t2 | ||
} | ||
isSimilar(t, t2i) | ||
case None => t1.symbol eq t2.symbol | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the logic was wrong here. If |
||
t2 match { | ||
case t2: Ident => | ||
t1.symbol eq t2.symbol | ||
case _ => // Select | ||
isSimilar(t2, t1) | ||
} | ||
case t1: Select => t2 match { | ||
case t2: Select => | ||
(t1.symbol eq t2.symbol) && | ||
isSimilar(t1.qualifier, t2.qualifier) | ||
case t2: Ident => desugarIdent(t2) match { | ||
case Some(t2) => isSimilar(t1, t2) | ||
case None => false | ||
case t2: Select => isSimilar(t1, t2) | ||
case _ => false | ||
} | ||
case _ => false | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,29 +149,15 @@ class Simplify extends MiniPhase with IdentityDenotTransformer { | |
|
||
object Simplify { | ||
import tpd._ | ||
// TODO: This function is duplicated in jvm/DottyBackendInterface.scala, let's factor these out! | ||
def desugarIdent(i: Ident)(implicit ctx: Context): Option[Select] = { | ||
i.tpe match { | ||
case TermRef(prefix: TermRef, _) => | ||
Some(ref(prefix).select(i.symbol)) | ||
case TermRef(prefix: ThisType, _) => | ||
Some(This(prefix.cls).select(i.symbol)) | ||
case _ => None | ||
} | ||
} | ||
|
||
/** Is this tree mutable, or java.lang.System.{in, out, err}? These three | ||
* System members are the only static final fields that are mutable. | ||
* See https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.4 | ||
*/ | ||
@tailrec def isEffectivelyMutable(t: Tree)(implicit ctx: Context): Boolean = t match { | ||
def isEffectivelyMutable(t: Tree)(implicit ctx: Context): Boolean = t match { | ||
case _ if t.symbol.is(Mutable) => true | ||
case s: Select => s.symbol.owner == defn.SystemModule | ||
case i: Ident => | ||
desugarIdent(i) match { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not understand why desugaring was needed here because it doesn't change the symbol of the tree |
||
case Some(ident) => isEffectivelyMutable(ident) | ||
case None => false | ||
} | ||
case _: Select | _: Ident => | ||
t.symbol.owner == defn.SystemModule | ||
case _ => false | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class A { | ||
var a = false | ||
} | ||
|
||
object B { | ||
var b = false | ||
} | ||
|
||
class C { | ||
var c = false | ||
} | ||
|
||
object C extends A { | ||
def test = { | ||
a = true | ||
C.a = true | ||
this.a = true | ||
C.this.a = true | ||
|
||
import B._ | ||
b = true | ||
|
||
val c0 = new C | ||
import c0._ | ||
c = true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not get rid of the
Option
here since the backend expects this signature