@@ -181,37 +181,28 @@ object Inlines:
181
181
// as its right hand side. The call to the wrapper unapply serves as the signpost for pattern matching.
182
182
// After pattern matching, the anonymous class is removed in phase InlinePatterns with a beta reduction step.
183
183
//
184
- // An inline unapply `P.unapply` in a plattern `P( x1,x2,...)` is transformed into
185
- // `{ class $anon { def unapply(t0: T0 )(using t1: T1, t2: T2, ...): R = P.unapply(t0)( using t1, t2, ...) }; new $anon }.unapply`
186
- // and the call `P.unapply( x1, x2, ...)` is inlined.
184
+ // An inline unapply `P.unapply` in a pattern `P[...](using ...)( x1,x2,...)(using t1: T1, t2: T2, ...)` is transformed into
185
+ // `{ class $anon { def unapply(s: S )(using t1: T1, t2: T2, ...): R = P.unapply[...](using ...)(s)( using t1, t2, ...) }; new $anon }.unapply(using y1,y2,...) `
186
+ // and the call `P.unapply[...](using ...)( x1, x2, ...)(using t1, t2 , ...)` is inlined.
187
187
// This serves as a placeholder for the inlined body until the `patternMatcher` phase. After pattern matcher
188
188
// transforms the patterns into terms, the `inlinePatterns` phase removes this anonymous class by β-reducing
189
189
// the call to the `unapply`.
190
190
191
- object SplitFunAndGivenArgs :
192
- def unapply (tree : Tree ): (Tree , List [List [Tree ]]) = tree match
193
- case Apply (SplitFunAndGivenArgs (fn, argss), args) => (fn, argss :+ args)
194
- case _ => (tree, Nil )
195
- val UnApply (SplitFunAndGivenArgs (fun, leadingImplicits), trailingImplicits, patterns) = unapp
196
- if leadingImplicits.flatten.nonEmpty then
197
- // To support them see https://github.com/lampepfl/dotty/pull/13158
198
- report.error(" inline unapply methods with given parameters before the scrutinee are not supported" , fun)
191
+ val UnApply (fun, trailingImplicits, patterns) = unapp
199
192
200
193
val sym = unapp.symbol
201
194
202
195
var unapplySym1 : Symbol = NoSymbol // created from within AnonClass() and used afterwards
203
196
204
197
val newUnapply = AnonClass (ctx.owner, List (defn.ObjectType ), sym.coord) { cls =>
205
- val targs = fun match
206
- case TypeApply (_, targs) => targs
207
- case _ => Nil
208
- val unapplyInfo = sym.info match
209
- case info : PolyType => info.instantiate(targs.map(_.tpe))
210
- case info => info
211
-
212
- val unapplySym = newSymbol(cls, sym.name.toTermName, Synthetic | Method , unapplyInfo, coord = sym.coord).entered
198
+ // `fun` is a partially applied method that contains all type applications of the method.
199
+ // The methodic type `fun.tpe.widen` is the type of the function starting from the scrutinee argument
200
+ // and its type parameters are instantiated.
201
+ val unapplySym = newSymbol(cls, sym.name.toTermName, Synthetic | Method , fun.tpe.widen, coord = sym.coord).entered
213
202
val unapply = DefDef (unapplySym.asTerm, argss =>
214
- inlineCall(fun.appliedToArgss(argss).withSpan(unapp.span))(using ctx.withOwner(unapplySym))
203
+ val body = fun.appliedToArgss(argss).withSpan(unapp.span)
204
+ if body.symbol.is(Transparent ) then inlineCall(body)(using ctx.withOwner(unapplySym))
205
+ else body
215
206
)
216
207
unapplySym1 = unapplySym
217
208
List (unapply)
0 commit comments