Skip to content

Commit 988d0b7

Browse files
committed
Add more error handling
1 parent 808ba77 commit 988d0b7

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ trait Applications extends Compatibility {
13821382
}
13831383

13841384
// named pattern
1385-
// TODO: Errors report the wrong position
1385+
// TODO: Errors report the wrong position if the name is the error
13861386
// TODO: Use proper error reporting
13871387
// TODO: Maybe the 'reorder' method above can be reused, or be template
13881388
if (bunchedArgs != Nil && argTypes != Nil) {
@@ -1414,6 +1414,9 @@ trait Applications extends Compatibility {
14141414

14151415
val namedArgs = bunchedArgs
14161416
.flatMap {
1417+
case pattern @ NamedArg(positionOfName(i), _) if i < unapplyPatterns.knownSize =>
1418+
report.error(i"${pattern.name} was already used as a positional pattern", pattern)
1419+
Seq.empty
14171420
case pattern @ NamedArg(positionOfName(_), _) => Seq(pattern)
14181421
case pattern @ NamedArg(unknownName, _) =>
14191422
if (positionOfStringNames.nonEmpty)
@@ -1432,8 +1435,6 @@ trait Applications extends Compatibility {
14321435

14331436

14341437
while (argTypes != Nil)
1435-
// TODO: calling knownSize is maybe to slow
1436-
// TODO: Same is maybe true for the call by name argument
14371438
val term = namedArgs.getOrElse(unapplyPatterns.knownSize, {
14381439
var ignore = underscore
14391440
ignore.span = unapplyFn.span

tests/neg/negNamedPatternMatching.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@
1818
24 | name = "Tom 3" // error
1919
| ^^^^^^^
2020
| 'name' was already used before
21+
-- Error: tests/neg/negNamedPatternMatching.scala:26:22 ----------------------------------------------------------------
22+
26 | case User(_, name = "Anna") => null // error
23+
| ^^^^^^
24+
| name was already used as a positional pattern

tests/neg/negNamedPatternMatching.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ val annasCity = user match
2222
name = "Tom",
2323
name = "Tom 2", // error
2424
name = "Tom 3" // error
25-
) => null
25+
) => null
26+
case User(_, name = "Anna") => null // error

0 commit comments

Comments
 (0)