@@ -59,7 +59,7 @@ class DropForMap extends MiniPhase:
5959 bindings.collectFirst:
6060 case vd : ValDef if f.sameTree(vd.rhs) =>
6161 expansion.find:
62- case Inlined (Thicket (Nil ), Nil , Ident (ident )) => ident == vd.name
62+ case Inlined (Thicket (Nil ), Nil , id @ Ident (vd.name )) => id.symbol eq vd.symbol
6363 case _ => false
6464 .getOrElse(expansion)
6565 .getOrElse(expansion)
@@ -75,14 +75,16 @@ class DropForMap extends MiniPhase:
7575
7676object DropForMap :
7777 val name : String = " dropForMap"
78- val description : String = " Drop unused trailing map calls in for comprehensions"
78+ val description : String = " drop unused trailing map calls in for comprehensions"
7979
80- // Extracts a fun from a possibly nested Apply with lambda and arbitrary implicit args.
81- // Specifically, an application `r.map(x => x)` is destructured into (r, map, args).
82- // If the receiver r was adapted, it is unwrapped.
83- // If `map` is an extension method, the nominal receiver is `args.head`.
80+ /** If the tree represents the trailing or terminal `map` of a for comprehension,
81+ * extracts a fun from a possibly nested Apply with lambda and arbitrary implicit args.
82+ * Specifically, an application `r.map(x => x)` is destructured into (r, map, args).
83+ * If the receiver r was adapted, it is unwrapped.
84+ * If `map` is an extension method, the nominal receiver is `args.head`.
85+ */
8486 private object Unmapped :
85- private def loop (tree : Tree , args : List [ Tree ] )(using Context ): Option [(Tree , Symbol , List [Tree ])] = tree match
87+ private def loop (tree : Tree )(using Context ): Option [(Tree , Symbol , List [Tree ])] = tree match
8688 case Apply (fun, args @ Lambda (_ :: Nil , _) :: Nil ) =>
8789 tree.removeAttachment(TrailingForMap ) match
8890 case Some (_) =>
@@ -92,15 +94,15 @@ object DropForMap:
9294 case _ => None
9395 case Apply (fun, _) =>
9496 fun.tpe match
95- case mt : MethodType if mt.isImplicitMethod => loop(fun, args )
97+ case mt : MethodType if mt.isImplicitMethod => loop(fun)
9698 case _ => None
97- case TypeApply (fun, _) => loop(fun, args )
99+ case TypeApply (fun, _) => loop(fun)
98100 case _ => None
99101 end loop
100102 def unapply (tree : Apply )(using Context ): Option [(Tree , Symbol , List [Tree ])] =
101103 tree.tpe match
102104 case _ : MethodOrPoly => None
103- case _ => loop(tree, args = Nil )
105+ case _ => loop(tree)
104106
105107 private object Lambda :
106108 def unapply (tree : Tree )(using Context ): Option [(List [ValDef ], Tree )] = tree match
@@ -124,7 +126,8 @@ object DropForMap:
124126 def unapply (tree : Tree )(using Context ): Option [Tree ] = tree match
125127 case Apply (fn @ Apply (_, _), _) => unapply(fn)
126128 case Apply (fn, r :: Nil )
127- if fn.symbol.is(Implicit ) || fn.symbol.name == nme.apply && fn.symbol.owner.derivesFrom(defn.ConversionClass )
129+ if fn.symbol.is(Implicit )
130+ || fn.symbol.name == nme.apply && fn.symbol.owner.derivesFrom(defn.ConversionClass )
128131 => Some (r)
129132 case TypeApply (fn, _) => unapply(fn)
130133 case _ => None
0 commit comments