Skip to content

Commit 0fce7a8

Browse files
committed
Fix error message
1 parent 5d32c75 commit 0fce7a8

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,9 +1362,10 @@ trait Applications extends Compatibility {
13621362
res.result()
13631363
}
13641364

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 {
13681369
case argType :: Nil =>
13691370
if (args.lengthCompare(1) > 0 && Feature.autoTuplingEnabled && defn.isTupleNType(argType)) untpd.Tuple(args) :: Nil
13701371
else args
@@ -1375,17 +1376,17 @@ trait Applications extends Compatibility {
13751376

13761377
// here add positional patterns to unapplyPatterns
13771378
// 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)
13801381
bunchedArgs = bunchedArgs.tail
1381-
argTypes = argTypes.tail
1382+
remainingArgTypes = remainingArgTypes.tail
13821383
}
13831384

13841385
// named pattern
13851386
// TODO: Errors report the wrong position if the name is the error
13861387
// TODO: Use proper error reporting
13871388
// TODO: Maybe the 'reorder' method above can be reused, or be template
1388-
if (bunchedArgs != Nil && argTypes != Nil) {
1389+
if (bunchedArgs != Nil && remainingArgTypes != Nil) {
13891390

13901391
val resTypeOfUnapplyFn = unapplyFn.tpe.widen.asInstanceOf[MethodType].resType
13911392

@@ -1436,18 +1437,18 @@ trait Applications extends Compatibility {
14361437
})
14371438

14381439

1439-
while (argTypes != Nil)
1440+
while (remainingArgTypes != Nil)
14401441
val term = namedArgs.getOrElse(unapplyPatterns.knownSize, {
14411442
var ignore = underscore
14421443
ignore.span = unapplyFn.span
14431444
ignore
14441445
})
1445-
unapplyPatterns += typed(term, argTypes.head)
1446-
argTypes = argTypes.tail
1446+
unapplyPatterns += typed(term, remainingArgTypes.head)
1447+
remainingArgTypes = remainingArgTypes.tail
14471448
} else {
14481449
// 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)
14511452
}
14521453

14531454
val result = assignType(cpy.UnApply(tree)(unapplyFn, unapplyImplicits(unapplyApp), unapplyPatterns.result), ownType)

compiler/test/dotty/tools/dotc/NamedPatternMatching.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty
22
package tools
33
package dotc
44

5-
import org.junit.{ Test, BeforeClass, AfterClass }
5+
import org.junit.Test
66
import org.junit.Assert._
77
import org.junit.Assume._
88
import org.junit.experimental.categories.Category
@@ -12,7 +12,6 @@ import java.nio.file._
1212
import java.util.stream.{ Stream => JStream }
1313
import scala.util.matching.Regex
1414
import scala.concurrent.duration._
15-
import TestSources.sources
1615
import vulpix._
1716

1817
class NamedPatternMatching {
@@ -35,6 +34,7 @@ class NamedPatternMatching {
3534
aggregateTests(
3635
compileFile("tests/neg/negNamedPatternMatching.scala", defaultOptions),
3736
compileFile("tests/neg/bad-unapplies.scala", defaultOptions),
37+
compileFile("tests/neg/i10757.scala", defaultOptions),
3838
).checkExpectedErrors()
3939
}
4040

0 commit comments

Comments
 (0)