Skip to content

Simplify decompiler printer for lambda #4255

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

Merged
merged 3 commits into from
Apr 6, 2018

Conversation

allanrenucci
Copy link
Contributor

No description provided.

{
(x: Int) => 2.+(x).+(4)
}
(x: Int) => 2.+(x).+(4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the result appear inside a "template" (class/trait)? Because then you sometimes do need parentheses around the closure to avoid (x: Int) => being parsed as a self-type declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, if one writes

class Test {
  ((x: Int) => x)
}

It will be pretty printed as

class Test() extends Object() { 
  (x: Int) => x
}

which will be parsed as a self type. But I do think the lightweight syntax is worth the newly introduced bug. One can fix the issue in a separate PR

@@ -3,10 +3,13 @@ out/posTestFromTasty/pos/lambda/foo/Foo.class
--------------------------------------------------------------------------------
package foo {
class Foo() extends Object() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase. extends Object is not printed anymore

}
override protected def blockToText[T >: Untyped](block: Block[T]): Text =
block match {
case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, _: Closure[T]) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract the RHS from the DefDef(..., rhs)` directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we extract the RHS using unapply? We have something like this:

case class DefDef(..., private var preRhs: LazyTree) {
  def rhs(implicit ctx) = forceIfLazy
}

I expect that the RHS should be accessed through def rhs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

@allanrenucci allanrenucci force-pushed the pretty-print-lambda branch from 5804f92 to 2143728 Compare April 6, 2018 08:50
@nicolasstucki nicolasstucki merged commit b37d9ff into scala:master Apr 6, 2018
@allanrenucci allanrenucci deleted the pretty-print-lambda branch April 6, 2018 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants