@@ -201,8 +201,8 @@ trait Printers
201
201
this += " Block(" ++= stats += " , " += expr += " )"
202
202
case If (cond, thenp, elsep) =>
203
203
this += " If(" += cond += " , " += thenp += " , " += elsep += " )"
204
- case Lambda (meth, tpt) =>
205
- this += " Lambda (" += meth += " , " += tpt += " )"
204
+ case Closure (meth, tpt) =>
205
+ this += " Closure (" += meth += " , " += tpt += " )"
206
206
case Match (selector, cases) =>
207
207
this += " Match(" += selector += " , " ++= cases += " )"
208
208
case ImpliedMatch (cases) =>
@@ -406,6 +406,7 @@ trait Printers
406
406
407
407
private implicit class TypeOps (buff : Buffer ) {
408
408
def += (x : TypeOrBounds ): Buffer = { visitType(x); buff }
409
+ def += (x : Option [TypeOrBounds ]): Buffer = { visitOption(x, visitType); buff }
409
410
def ++= (x : List [TypeOrBounds ]): Buffer = { visitList(x, visitType); buff }
410
411
}
411
412
@@ -740,17 +741,6 @@ trait Printers
740
741
printTree(body)
741
742
}
742
743
743
- case IsDefDef (ddef @ DefDef (name, targs, argss, _, rhsOpt)) if name.startsWith(" $anonfun" ) =>
744
- // Decompile lambda definition
745
- assert(targs.isEmpty)
746
- val args :: Nil = argss
747
- val Some (rhs) = rhsOpt
748
- inParens {
749
- printArgsDefs(args)
750
- this += " => "
751
- printTree(rhs)
752
- }
753
-
754
744
case IsDefDef (ddef @ DefDef (name, targs, argss, tpt, rhs)) =>
755
745
printDefAnnotations(ddef)
756
746
@@ -901,6 +891,13 @@ trait Printers
901
891
this += " = "
902
892
printTree(rhs)
903
893
894
+ case Lambda (params, body) => // must come before `Block`
895
+ inParens {
896
+ printArgsDefs(params)
897
+ this += " => "
898
+ printTree(body)
899
+ }
900
+
904
901
case Block (stats0, expr) =>
905
902
val stats = stats0.filter {
906
903
case IsValDef (tree) => ! tree.symbol.flags.is(Flags .Object )
@@ -911,10 +908,6 @@ trait Printers
911
908
case Inlined (_, bindings, expansion) =>
912
909
printFlatBlock(bindings, expansion)
913
910
914
- case Lambda (meth, tpt) =>
915
- // Printed in by it's DefDef
916
- this
917
-
918
911
case If (cond, thenp, elsep) =>
919
912
this += highlightKeyword(" if " )
920
913
inParens(printTree(cond))
@@ -982,6 +975,8 @@ trait Printers
982
975
def flatBlock (stats : List [Statement ], expr : Term ): (List [Statement ], Term ) = {
983
976
val flatStats = List .newBuilder[Statement ]
984
977
def extractFlatStats (stat : Statement ): Unit = stat match {
978
+ case Lambda (_, _) => // must come before `Block`
979
+ flatStats += stat
985
980
case Block (stats1, expr1) =>
986
981
val it = stats1.iterator
987
982
while (it.hasNext)
@@ -996,6 +991,8 @@ trait Printers
996
991
case stat => flatStats += stat
997
992
}
998
993
def extractFlatExpr (term : Term ): Term = term match {
994
+ case Lambda (_, _) => // must come before `Block`
995
+ term
999
996
case Block (stats1, expr1) =>
1000
997
val it = stats1.iterator
1001
998
while (it.hasNext)
@@ -1017,23 +1014,16 @@ trait Printers
1017
1014
1018
1015
def printFlatBlock (stats : List [Statement ], expr : Term )(implicit elideThis : Option [Symbol ]): Buffer = {
1019
1016
val (stats1, expr1) = flatBlock(stats, expr)
1020
- // Remove Lambda nodes, lambdas are printed by their definition
1021
1017
val stats2 = stats1.filter {
1022
- case Lambda (_, _ ) => false
1018
+ case IsTypeDef (tree ) => ! tree.symbol.annots.exists(_.symbol.owner.fullName == " scala.internal.Quoted$.quoteTypeTag " )
1023
1019
case _ => true
1024
1020
}
1025
- val (stats3, expr3) = expr1 match {
1026
- case Lambda (_, _) =>
1027
- val init :+ last = stats2
1028
- (init, last)
1029
- case _ => (stats2, expr1)
1030
- }
1031
- if (stats3.isEmpty) {
1032
- printTree(expr3)
1021
+ if (stats2.isEmpty) {
1022
+ printTree(expr1)
1033
1023
} else {
1034
1024
this += " {"
1035
1025
indented {
1036
- printStats(stats3, expr3 )
1026
+ printStats(stats2, expr1 )
1037
1027
}
1038
1028
this += lineBreak() += " }"
1039
1029
}
@@ -1043,6 +1033,7 @@ trait Printers
1043
1033
def printSeparator (next : Tree ): Unit = {
1044
1034
// Avoid accidental application of opening `{` on next line with a double break
1045
1035
def rec (next : Tree ): Unit = next match {
1036
+ case Lambda (_, _) => this += lineBreak()
1046
1037
case Block (stats, _) if stats.nonEmpty => this += doubleLineBreak()
1047
1038
case Inlined (_, bindings, _) if bindings.nonEmpty => this += doubleLineBreak()
1048
1039
case Select (qual, _) => rec(qual)
0 commit comments