@@ -149,7 +149,7 @@ object Applications {
149
149
(0 until argsNum).map(i => if (i < arity - 1 ) selTps(i) else elemTp).toList
150
150
}
151
151
152
- def unapplyArgs (unapplyResult : Type , unapplyFn : Tree , args : List [untpd.Tree ], pos : SrcPos )(using Context ): List [Type ] = {
152
+ def unapplyArgs (unapplyResult : Type , unapplyFn : Tree , args : List [untpd.Tree ], pos : SrcPos )(using Context ): List [Type ] =
153
153
def getName (fn : Tree ): Name =
154
154
fn match
155
155
case TypeApply (fn, _) => getName(fn)
@@ -164,46 +164,36 @@ object Applications {
164
164
Nil
165
165
}
166
166
167
- def unapplySeq (tp : Type )(fallback : => List [Type ]): List [Type ] = {
167
+ def unapplySeq (tp : Type )(fallback : => List [Type ]): List [Type ] =
168
168
val elemTp = unapplySeqTypeElemTp(tp)
169
- if (elemTp.exists) args.map(Function .const(elemTp))
170
- else if (isProductSeqMatch(tp, args.length, pos)) productSeqSelectors(tp, args.length, pos)
171
- else if tp.derivesFrom(defn.NonEmptyTupleClass ) then foldApplyTupleType(tp)
169
+ if elemTp.exists then
170
+ args.map(Function .const(elemTp))
171
+ else if isProductSeqMatch(tp, args.length, pos) then
172
+ productSeqSelectors(tp, args.length, pos)
173
+ else if tp.derivesFrom(defn.NonEmptyTupleClass ) then
174
+ tp.tupleElementTypes.getOrElse(Nil )
172
175
else fallback
173
- }
174
176
175
- if ( unapplyName == nme.unapplySeq)
176
- unapplySeq(unapplyResult) {
177
+ if unapplyName == nme.unapplySeq then
178
+ unapplySeq(unapplyResult):
177
179
if (isGetMatch(unapplyResult, pos)) unapplySeq(getTp)(fail)
178
180
else fail
179
- }
180
- else {
181
+ else
181
182
assert(unapplyName == nme.unapply)
182
- if ( isProductMatch(unapplyResult, args.length, pos))
183
+ if isProductMatch(unapplyResult, args.length, pos) then
183
184
productSelectorTypes(unapplyResult, pos)
184
- else if ( isGetMatch(unapplyResult, pos))
185
+ else if isGetMatch(unapplyResult, pos) then
185
186
getUnapplySelectors(getTp, args, pos)
186
- else if ( unapplyResult.widenSingleton isRef defn.BooleanClass )
187
+ else if unapplyResult.derivesFrom( defn.BooleanClass ) then
187
188
Nil
188
- else if ( defn.isProductSubType(unapplyResult) && productArity(unapplyResult, pos) != 0 )
189
+ else if defn.isProductSubType(unapplyResult) && productArity(unapplyResult, pos) != 0 then
189
190
productSelectorTypes(unapplyResult, pos)
190
191
// this will cause a "wrong number of arguments in pattern" error later on,
191
192
// which is better than the message in `fail`.
192
193
else if unapplyResult.derivesFrom(defn.NonEmptyTupleClass ) then
193
- foldApplyTupleType( unapplyResult)
194
+ unapplyResult.tupleElementTypes.getOrElse( Nil )
194
195
else fail
195
- }
196
- }
197
-
198
- def foldApplyTupleType (tp : Type )(using Context ): List [Type ] =
199
- object tupleFold extends TypeAccumulator [List [Type ]]:
200
- override def apply (accum : List [Type ], t : Type ): List [Type ] =
201
- t match
202
- case AppliedType (tycon, x :: x2 :: Nil ) if tycon.typeSymbol == defn.PairClass =>
203
- apply(x :: accum, x2)
204
- case x => foldOver(accum, x)
205
- end tupleFold
206
- tupleFold(Nil , tp).reverse
196
+ end unapplyArgs
207
197
208
198
def wrapDefs (defs : mutable.ListBuffer [Tree ] | Null , tree : Tree )(using Context ): Tree =
209
199
if (defs != null && defs.nonEmpty) tpd.Block (defs.toList, tree) else tree
0 commit comments