Skip to content

Commit 8fe1d75

Browse files
committed
Simplify reflect Printers with extractor for function literal
1 parent c660d4c commit 8fe1d75

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -741,17 +741,6 @@ trait Printers
741741
printTree(body)
742742
}
743743

744-
case IsDefDef(ddef @ DefDef(name, targs, argss, _, rhsOpt)) if name.startsWith("$anonfun") =>
745-
// Decompile lambda definition
746-
assert(targs.isEmpty)
747-
val args :: Nil = argss
748-
val Some(rhs) = rhsOpt
749-
inParens {
750-
printArgsDefs(args)
751-
this += " => "
752-
printTree(rhs)
753-
}
754-
755744
case IsDefDef(ddef @ DefDef(name, targs, argss, tpt, rhs)) =>
756745
printDefAnnotations(ddef)
757746

@@ -912,9 +901,13 @@ trait Printers
912901
case Inlined(_, bindings, expansion) =>
913902
printFlatBlock(bindings, expansion)
914903

915-
case Closure(meth, tpt) =>
916-
// Printed in by it's DefDef
917-
this
904+
case Lambda(params, body) =>
905+
inParens {
906+
printArgsDefs(params)
907+
this += " => "
908+
printTree(body)
909+
}
910+
918911

919912
case If(cond, thenp, elsep) =>
920913
this += highlightKeyword("if ")
@@ -1018,24 +1011,16 @@ trait Printers
10181011

10191012
def printFlatBlock(stats: List[Statement], expr: Term)(implicit elideThis: Option[Symbol]): Buffer = {
10201013
val (stats1, expr1) = flatBlock(stats, expr)
1021-
// Remove Lambda nodes, lambdas are printed by their definition
10221014
val stats2 = stats1.filter {
1023-
case Closure(_, _) => false
10241015
case IsTypeDef(tree) => !tree.symbol.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag")
10251016
case _ => true
10261017
}
1027-
val (stats3, expr3) = expr1 match {
1028-
case Closure(_, _) =>
1029-
val init :+ last = stats2
1030-
(init, last)
1031-
case _ => (stats2, expr1)
1032-
}
1033-
if (stats3.isEmpty) {
1034-
printTree(expr3)
1018+
if (stats2.isEmpty) {
1019+
printTree(expr1)
10351020
} else {
10361021
this += "{"
10371022
indented {
1038-
printStats(stats3, expr3)
1023+
printStats(stats2, expr1)
10391024
}
10401025
this += lineBreak() += "}"
10411026
}

0 commit comments

Comments
 (0)