-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2964: Refresh names for anonymous classes #2999
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
Conversation
ba22b2b
to
1c61bdf
Compare
|
||
override def phaseName = "liftedClasses" | ||
|
||
override def runsAfterGroupsOf: Set[Class[_ <: Phases.Phase]] = Set(classOf[Flatten]) |
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.
It's not really flatten, but RestoreScopes.
@@ -16,6 +17,8 @@ class TransformWildcards extends MiniPhaseTransform with IdentityDenotTransforme | |||
|
|||
override def phaseName = "transformWildcards" | |||
|
|||
override def runsAfter: Set[Class[_ <: Phases.Phase]] = Set(classOf[LiftedClasses]) |
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.
Why is there a dependency between those two phases?
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.
Only checked experimentally. It failed if I put it afterward, therefore I added the explicit runsAfter
to make this evident to anyone that tries to reorder phases.
else tree | ||
|
||
private def needsRefresh(sym: Symbol)(implicit ctx: Context): Boolean = | ||
sym.isClass && !sym.is(Package) && sym.name.is(UniqueName) |
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.
Do we have packages with UniqueName?
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.
Why do you apply it only to classes, don't we have the same issue with methods that are lifted out?
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.
class Foo {
def ann = {
def foo() = 1;
}
}
class Bar {
def ann = {
def foo() = 1;
}
}
public class Foo {
public void ann() {
}
private static int foo$1() {
return 1;
}
}
public class Bar {
public void ann() {
}
private static int foo$2() { // <--- same issue
return 1;
}
}
/** Renames lifted classes to local numbering scheme */ | ||
class LiftedClasses extends MiniPhaseTransform with SymTransformer { thisTransformer => | ||
|
||
override def phaseName = "liftedClasses" |
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.
renameLifted?
@DarkDimius the requested changes have been made. |
Code has been rewritten since last review
|
||
/** Refreshes the number of the name based on the full name of the symbol */ | ||
private def refreshedName(sym: Symbol)(implicit ctx: Context): Name = { | ||
lazy val rewriteUnique: PartialFunction[Name, Name] = { |
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.
Why lazy?
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.
Oh I see, that's a funny way to write recursion 😄
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.
Do you know a cleaner way to define recursive partial functions?
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 would do it with a def
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.
Changed it. Though now it will create a new instance of the function each iteration, I guess this should not happen too often.
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.
LGTM!
37e667e
to
fe7ac0a
Compare
No description provided.