@@ -1362,9 +1362,10 @@ trait Applications extends Compatibility {
1362
1362
res.result()
1363
1363
}
1364
1364
1365
- var argTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.srcPos)
1366
- for (argType <- argTypes) assert(! isBounds(argType), unapplyApp.tpe.show)
1367
- var bunchedArgs = argTypes match {
1365
+ val allArgTypes = unapplyArgs(unapplyApp.tpe, unapplyFn, args, tree.srcPos)
1366
+ var remainingArgTypes = allArgTypes
1367
+ for (argType <- remainingArgTypes) assert(! isBounds(argType), unapplyApp.tpe.show)
1368
+ var bunchedArgs = remainingArgTypes match {
1368
1369
case argType :: Nil =>
1369
1370
if (args.lengthCompare(1 ) > 0 && Feature .autoTuplingEnabled && defn.isTupleNType(argType)) untpd.Tuple (args) :: Nil
1370
1371
else args
@@ -1375,17 +1376,17 @@ trait Applications extends Compatibility {
1375
1376
1376
1377
// here add positional patterns to unapplyPatterns
1377
1378
// TODO: isInstanceOf seems not to be the right tool
1378
- while (bunchedArgs != Nil && argTypes != Nil && ! bunchedArgs.head.isInstanceOf [dotty.tools.dotc.ast.Trees .NamedArg [_]]) {
1379
- unapplyPatterns += typed(bunchedArgs.head, argTypes .head)
1379
+ while (bunchedArgs != Nil && remainingArgTypes != Nil && ! bunchedArgs.head.isInstanceOf [dotty.tools.dotc.ast.Trees .NamedArg [_]]) {
1380
+ unapplyPatterns += typed(bunchedArgs.head, remainingArgTypes .head)
1380
1381
bunchedArgs = bunchedArgs.tail
1381
- argTypes = argTypes .tail
1382
+ remainingArgTypes = remainingArgTypes .tail
1382
1383
}
1383
1384
1384
1385
// named pattern
1385
1386
// TODO: Errors report the wrong position if the name is the error
1386
1387
// TODO: Use proper error reporting
1387
1388
// TODO: Maybe the 'reorder' method above can be reused, or be template
1388
- if (bunchedArgs != Nil && argTypes != Nil ) {
1389
+ if (bunchedArgs != Nil && remainingArgTypes != Nil ) {
1389
1390
1390
1391
val resTypeOfUnapplyFn = unapplyFn.tpe.widen.asInstanceOf [MethodType ].resType
1391
1392
@@ -1436,18 +1437,18 @@ trait Applications extends Compatibility {
1436
1437
})
1437
1438
1438
1439
1439
- while (argTypes != Nil )
1440
+ while (remainingArgTypes != Nil )
1440
1441
val term = namedArgs.getOrElse(unapplyPatterns.knownSize, {
1441
1442
var ignore = underscore
1442
1443
ignore.span = unapplyFn.span
1443
1444
ignore
1444
1445
})
1445
- unapplyPatterns += typed(term, argTypes .head)
1446
- argTypes = argTypes .tail
1446
+ unapplyPatterns += typed(term, remainingArgTypes .head)
1447
+ remainingArgTypes = remainingArgTypes .tail
1447
1448
} else {
1448
1449
// Check for positional arguments
1449
- if (argTypes != Nil || bunchedArgs != Nil )
1450
- report.error(UnapplyInvalidNumberOfArguments (qual, argTypes ), tree.srcPos)
1450
+ if (remainingArgTypes != Nil || bunchedArgs != Nil )
1451
+ report.error(UnapplyInvalidNumberOfArguments (qual, allArgTypes ), tree.srcPos)
1451
1452
}
1452
1453
1453
1454
val result = assignType(cpy.UnApply (tree)(unapplyFn, unapplyImplicits(unapplyApp), unapplyPatterns.result), ownType)
0 commit comments