@@ -190,14 +190,19 @@ object Inliner {
190
190
// as its right hand side. The call to the wrapper unapply serves as the signpost for pattern matching.
191
191
// After pattern matching, the anonymous class is removed in phase InlinePatterns with a beta reduction step.
192
192
//
193
- // An inline unapply `P.unapply` in a plattern `P(x1,x2,...)` is transformed into
194
- // `{ class $anon { def unapply(t0: T0)( using t1: T1, t2: T2, ...): R = P.unapply(t0)( using t1, t2, ...) }; new $anon }.unapply`
195
- // and the call `P.unapply(x1, x2, ...)` is inlined.
193
+ // An inline unapply `P.unapply` in a pattern `P(using y1,y2,...) (x1,x2,...)` is transformed into
194
+ // `{ 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,...) `
195
+ // and the call `P.unapply(using l1, l2,...)( x1, x2, ...)(using t1, t2 , ...)` is inlined.
196
196
// This serves as a placeholder for the inlined body until the `patternMatcher` phase. After pattern matcher
197
197
// transforms the patterns into terms, the `inlinePatterns` phase removes this anonymous class by β-reducing
198
198
// the call to the `unapply`.
199
199
200
- val UnApply (fun, implicits, patterns) = unapp
200
+ object SplitFunAndGivenArgs :
201
+ def unapply (tree : Tree ): (Tree , List [List [Tree ]]) = tree match
202
+ case Apply (SplitFunAndGivenArgs (fn, argss), args) => (fn, argss :+ args)
203
+ case _ => (tree, Nil )
204
+
205
+ val UnApply (SplitFunAndGivenArgs (fun, givenArgss) , implicits, patterns) = unapp
201
206
val sym = unapp.symbol
202
207
val cls = newNormalizedClassSymbol(ctx.owner, tpnme.ANON_CLASS , Synthetic | Final , List (defn.ObjectType ), newScope, coord = sym.coord)
203
208
val constr = newConstructor(cls, Synthetic , Nil , Nil , coord = sym.coord).entered
@@ -209,13 +214,15 @@ object Inliner {
209
214
case info : PolyType => info.instantiate(targs.map(_.tpe))
210
215
case info => info
211
216
212
- val unappplySym = newSymbol(cls, sym.name.toTermName, Synthetic | Method , unapplyInfo, coord = sym.coord).entered
213
- val unapply = DefDef (unappplySym , argss =>
214
- inlineCall( fun.appliedToArgss(argss).withSpan(unapp.span))( using ctx.withOwner(unappplySym) )
217
+ val unapplySym = newSymbol(cls, sym.name.toTermName, Synthetic | Method , unapplyInfo, coord = sym.coord).entered
218
+ val unapply = DefDef (unapplySym , argss =>
219
+ fun.appliedToArgss(argss).withSpan(unapp.span)
215
220
)
221
+
216
222
val cdef = ClassDef (cls, DefDef (constr), List (unapply))
217
223
val newUnapply = Block (cdef :: Nil , New (cls.typeRef, Nil ))
218
- val newFun = newUnapply.select(unappplySym).withSpan(unapp.span)
224
+ val newFun = newUnapply.select(unapplySym).withSpan(unapp.span).appliedToArgss(givenArgss)
225
+
219
226
cpy.UnApply (unapp)(newFun, implicits, patterns)
220
227
}
221
228
0 commit comments