@@ -109,6 +109,10 @@ object Applications {
109
109
if (isValid) elemTp else NoType
110
110
}
111
111
112
+ def namedTupleOrProductTypes (tp : Type )(using Context ): List [Type ] =
113
+ if tp.isNamedTupleType then tp.namedTupleElementTypes.map(_(1 ))
114
+ else productSelectorTypes(tp, NoSourcePosition )
115
+
112
116
def productSelectorTypes (tp : Type , errorPos : SrcPos )(using Context ): List [Type ] = {
113
117
val sels = for (n <- Iterator .from(0 )) yield extractorMemberType(tp, nme.selectorName(n), errorPos)
114
118
sels.takeWhile(_.exists).toList
@@ -177,9 +181,14 @@ object Applications {
177
181
else fallback
178
182
179
183
private def tryAdaptPatternArgs (elems : List [untpd.Tree ], pt : Type )(using Context ): Option [List [untpd.Tree ]] =
180
- tryEither[Option [List [untpd.Tree ]]]
181
- (Some (desugar.adaptPatternArgs(elems, pt)))
182
- ((_, _) => None )
184
+ namedTupleOrProductTypes(pt) match
185
+ case List (defn.NamedTuple (_, _))=>
186
+ // if the product types list is a singleton named tuple, autotupling might be applied, so don't fail eagerly
187
+ tryEither[Option [List [untpd.Tree ]]]
188
+ (Some (desugar.adaptPatternArgs(elems, pt)))
189
+ ((_, _) => None )
190
+ case pts =>
191
+ Some (desugar.adaptPatternArgs(elems, pt))
183
192
184
193
private def getUnapplySelectors (tp : Type )(using Context ): List [Type ] =
185
194
// We treat patterns as product elements if
@@ -199,7 +208,7 @@ object Applications {
199
208
else tp :: Nil
200
209
201
210
private def productUnapplySelectors (tp : Type )(using Context ): Option [List [Type ]] =
202
- if defn.isProductSubType(tp) then
211
+ if defn.isProductSubType(tp) && args.lengthCompare(productArity(tp)) <= 0 then
203
212
tryAdaptPatternArgs(args, tp) match
204
213
case Some (args1) if isProductMatch(tp, args1.length, pos) =>
205
214
args = args1
0 commit comments