Skip to content

Commit a147fba

Browse files
committed
Fix reflect printers: Lambda case should come before Block
1 parent 575f989 commit a147fba

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,13 @@ trait Printers
891891
this += " = "
892892
printTree(rhs)
893893

894+
case Lambda(params, body) => // must come before `Block`
895+
inParens {
896+
printArgsDefs(params)
897+
this += " => "
898+
printTree(body)
899+
}
900+
894901
case Block(stats0, expr) =>
895902
val stats = stats0.filter {
896903
case IsValDef(tree) => !tree.symbol.flags.is(Flags.Object)
@@ -901,14 +908,6 @@ trait Printers
901908
case Inlined(_, bindings, expansion) =>
902909
printFlatBlock(bindings, expansion)
903910

904-
case Lambda(params, body) =>
905-
inParens {
906-
printArgsDefs(params)
907-
this += " => "
908-
printTree(body)
909-
}
910-
911-
912911
case If(cond, thenp, elsep) =>
913912
this += highlightKeyword("if ")
914913
inParens(printTree(cond))

library/src/scala/tasty/reflect/TreeOps.scala

+3
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@ trait TreeOps extends Core {
582582
* closure(m)
583583
* }
584584
*
585+
* @note Due to the encoding, in pattern matches the case for `Lambda`
586+
* should come before the case for `Block` to avoid mishandling
587+
* of `Lambda`.
585588
*/
586589
object Lambda {
587590
def unapply(tree: Tree)(implicit ctx: Context): Option[(List[ValDef], Term)] = tree match {

0 commit comments

Comments
 (0)