@@ -187,14 +187,19 @@ object Inliner {
187187 // as its right hand side. The call to the wrapper unapply serves as the signpost for pattern matching.
188188 // After pattern matching, the anonymous class is removed in phase InlinePatterns with a beta reduction step.
189189 //
190- // An inline unapply `P.unapply` in a plattern `P(x1,x2,...)` is transformed into
191- // `{ class $anon { def unapply(t0: T0)( using t1: T1, t2: T2, ...): R = P.unapply(t0)( using t1, t2, ...) }; new $anon }.unapply`
192- // and the call `P.unapply(x1, x2, ...)` is inlined.
190+ // An inline unapply `P.unapply` in a pattern `P(using y1,y2,...) (x1,x2,...)` is transformed into
191+ // `{ class $anon { def unapply(using l1: L1, l2: L2, ...)(s: S)( using t1: T1, t2: T2, ...): R = P.unapply(using l1, l2, ...)(s)( using t1, t2, ...) }; new $anon }.unapply(using y1,y2,...) `
192+ // and the call `P.unapply(using l1, l2,...)( x1, x2, ...)(using t1, t2 , ...)` is inlined.
193193 // This serves as a placeholder for the inlined body until the `patternMatcher` phase. After pattern matcher
194194 // transforms the patterns into terms, the `inlinePatterns` phase removes this anonymous class by β-reducing
195195 // the call to the `unapply`.
196196
197- val UnApply (fun, implicits, patterns) = unapp
197+ object SplitFunAndGivenArgs :
198+ def unapply (tree : Tree ): (Tree , List [List [Tree ]]) = tree match
199+ case Apply (SplitFunAndGivenArgs (fn, argss), args) => (fn, argss :+ args)
200+ case _ => (tree, Nil )
201+
202+ val UnApply (SplitFunAndGivenArgs (fun, givenArgss) , implicits, patterns) = unapp
198203 val sym = unapp.symbol
199204 val cls = newNormalizedClassSymbol(ctx.owner, tpnme.ANON_CLASS , Synthetic | Final , List (defn.ObjectType ), coord = sym.coord)
200205 val constr = newConstructor(cls, Synthetic , Nil , Nil , coord = sym.coord).entered
@@ -206,13 +211,15 @@ object Inliner {
206211 case info : PolyType => info.instantiate(targs.map(_.tpe))
207212 case info => info
208213
209- val unappplySym = newSymbol(cls, sym.name.toTermName, Synthetic | Method , unapplyInfo, coord = sym.coord).entered
210- val unapply = DefDef (unappplySym , argss =>
211- inlineCall( fun.appliedToArgss(argss).withSpan(unapp.span))( using ctx.withOwner(unappplySym) )
214+ val unapplySym = newSymbol(cls, sym.name.toTermName, Synthetic | Method , unapplyInfo, coord = sym.coord).entered
215+ val unapply = DefDef (unapplySym , argss =>
216+ fun.appliedToArgss(argss).withSpan(unapp.span)
212217 )
218+
213219 val cdef = ClassDef (cls, DefDef (constr), List (unapply))
214220 val newUnapply = Block (cdef :: Nil , New (cls.typeRef, Nil ))
215- val newFun = newUnapply.select(unappplySym).withSpan(unapp.span)
221+ val newFun = newUnapply.select(unapplySym).withSpan(unapp.span).appliedToArgss(givenArgss)
222+
216223 cpy.UnApply (unapp)(newFun, implicits, patterns)
217224 }
218225
0 commit comments