-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix decompilation of while loops #4584
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
@odersky here are some examples of |
We are bout to disallow inline parameters of function type anyway. So should we close this commit? |
I will remove the inline function part and keep the by name functions as regression tests |
* Show that there is no semantic difference between inline functions and by name functions
c1b4c72
to
3e8b773
Compare
Found a regression |
@@ -225,7 +245,14 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty | |||
this += " = " | |||
printTree(rhs) | |||
|
|||
case Term.Block(stats, expr) => | |||
case Term.Block(stats0, expr) => | |||
def isLoopContinue(tree: Tree): Boolean = tree match { |
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.
Rename is isLoopEntryPoint
?
3e8b773
to
fdff56e
Compare
fdff56e
to
9db9d9b
Compare
@allanrenucci this needs a review as the code completely changed |
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.
Otherwise LGTM
printTree(cond) | ||
this += ")" | ||
|
||
case expr if isLoopEntryPoint(expr) && stats.size == 1 => |
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 think it would be cleaner to have this case be part of the extractor:
def unapply(arg: Tree)(implicit ctx: Context): Option[(Term, List[Statement])] = arg match {
case DefDef("while$", _, _, _, Some(Term.If(cond, Term.Block(bodyStats, _), _))) => Some((cond, bodyStats))
case Block(List(tree), _) => unapply(tree)
case _ => None
}
@@ -753,6 +748,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty | |||
private object While { | |||
def unapply(arg: Tree)(implicit ctx: Context): Option[(Term, List[Statement])] = arg match { | |||
case DefDef("while$", _, _, _, Some(Term.If(cond, Term.Block(bodyStats, _), _))) => Some((cond, bodyStats)) | |||
case Term.Block(List(tree), _) => unapply(tree) |
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 suppose you will need to add the same case for the DoWhile
extractor
612feb2
to
75b315b
Compare
Show that there is no semantic difference between inline functions and by name functions.