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