@@ -1260,28 +1260,41 @@ trait Applications extends Compatibility {
1260
1260
*/
1261
1261
def trySelectUnapply (qual : untpd.Tree )(fallBack : (Tree , TyperState ) => Tree ): Tree = {
1262
1262
// try first for non-overloaded, then for overloaded ocurrences
1263
- def tryWithName (name : TermName )(fallBack : (Tree , TyperState ) => Tree )(using Context ): Tree = {
1264
- def tryWithProto (pt : Type )(using Context ) = {
1265
- val result = typedExpr(untpd.Select (qual, name), new UnapplyFunProto (pt, this ))
1263
+ def tryWithName (name : TermName )(fallBack : (Tree , TyperState ) => Tree )(using Context ): Tree =
1264
+
1265
+ def tryWithProto (qual : untpd.Tree , targs : List [Tree ], pt : Type )(using Context ) =
1266
+ val proto = UnapplyFunProto (pt, this )
1267
+ val unapp = untpd.Select (qual, name)
1268
+ val result =
1269
+ if targs.isEmpty then typedExpr(unapp, proto)
1270
+ else typedExpr(unapp, PolyProto (targs, proto)).appliedToTypeTrees(targs)
1266
1271
if ! result.symbol.exists
1267
1272
|| result.symbol.name == name
1268
1273
|| ctx.reporter.hasErrors
1269
1274
then result
1270
1275
else notAnExtractor(result)
1271
1276
// It might be that the result of typedExpr is an `apply` selection or implicit conversion.
1272
1277
// Reject in this case.
1273
- }
1274
- tryEither {
1275
- tryWithProto(selType)
1276
- } {
1277
- (sel, state) =>
1278
- tryEither {
1279
- tryWithProto(WildcardType )
1280
- } {
1281
- (_, _) => fallBack(sel, state)
1282
- }
1283
- }
1284
- }
1278
+
1279
+ def tryWithTypeArgs (qual : untpd.Tree , targs : List [Tree ])(fallBack : (Tree , TyperState ) => Tree ): Tree =
1280
+ tryEither {
1281
+ tryWithProto(qual, targs, selType)
1282
+ } {
1283
+ (sel, state) =>
1284
+ tryEither {
1285
+ tryWithProto(qual, targs, WildcardType )
1286
+ } {
1287
+ (_, _) => fallBack(sel, state)
1288
+ }
1289
+ }
1290
+
1291
+ qual match
1292
+ case TypeApply (qual1, targs) =>
1293
+ tryWithTypeArgs(qual1, targs.mapconserve(typedType(_)))((t, ts) =>
1294
+ tryWithTypeArgs(qual, Nil )(fallBack))
1295
+ case _ =>
1296
+ tryWithTypeArgs(qual, Nil )(fallBack)
1297
+ end tryWithName
1285
1298
1286
1299
// try first for unapply, then for unapplySeq
1287
1300
tryWithName(nme.unapply) {
0 commit comments