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