File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -1382,7 +1382,7 @@ trait Applications extends Compatibility {
1382
1382
}
1383
1383
1384
1384
// named pattern
1385
- // TODO: Errors report the wrong position
1385
+ // TODO: Errors report the wrong position if the name is the error
1386
1386
// TODO: Use proper error reporting
1387
1387
// TODO: Maybe the 'reorder' method above can be reused, or be template
1388
1388
if (bunchedArgs != Nil && argTypes != Nil ) {
@@ -1414,6 +1414,9 @@ trait Applications extends Compatibility {
1414
1414
1415
1415
val namedArgs = bunchedArgs
1416
1416
.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
1417
1420
case pattern @ NamedArg (positionOfName(_), _) => Seq (pattern)
1418
1421
case pattern @ NamedArg (unknownName, _) =>
1419
1422
if (positionOfStringNames.nonEmpty)
@@ -1432,8 +1435,6 @@ trait Applications extends Compatibility {
1432
1435
1433
1436
1434
1437
while (argTypes != Nil )
1435
- // TODO: calling knownSize is maybe to slow
1436
- // TODO: Same is maybe true for the call by name argument
1437
1438
val term = namedArgs.getOrElse(unapplyPatterns.knownSize, {
1438
1439
var ignore = underscore
1439
1440
ignore.span = unapplyFn.span
Original file line number Diff line number Diff line change 18
18
24 | name = "Tom 3" // error
19
19
| ^^^^^^^
20
20
| '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
Original file line number Diff line number Diff line change @@ -22,4 +22,5 @@ val annasCity = user match
22
22
name = " Tom" ,
23
23
name = " Tom 2" , // error
24
24
name = " Tom 3" // error
25
- ) => null
25
+ ) => null
26
+ case User (_, name = " Anna" ) => null // error
You can’t perform that action at this time.
0 commit comments