@@ -1393,29 +1393,31 @@ trait Applications extends Compatibility {
1393
1393
.memberDenots(typeNameFilter, (name, buf) => if (name.toString == " Names" ) buf += typeInfoOfGetMethod.member(name).asSingleDenotation)
1394
1394
.headOption
1395
1395
1396
+ val positionOfStringNames : Map [String , Int ] =
1397
+ if names.isDefined then
1398
+ // TODO: Don't use regular expression to deconstruct tuples
1399
+ val reg = " \" ([^\" ]+)\" " .r
1400
+ reg.findAllMatchIn(names.get.showDcl)
1401
+ .map(_.group(1 ))
1402
+ .zipWithIndex
1403
+ .toMap
1404
+ // TODO: The test should actually be: is unapplyFn generated by the compiler because we have a case class?
1405
+ else if unapplyFn.tpe.widen.paramInfoss.head.head.typeSymbol.is(CaseClass ) then
1406
+ unapplyFn.tpe.widen.paramInfoss.head.head.fields.map(_.name.toString).zipWithIndex.toMap
1407
+ else
1408
+ report.error(i " ' ${qual}' doesn't support named patterns " , qual)
1409
+ Map .empty
1410
+
1396
1411
val positionOfName : PartialFunction [Name , Int ] =
1397
- if names.isDefined then
1398
- // TODO: Don't use regular expression to deconstruct tuples
1399
- val reg = " \" ([^\" ]+)\" " .r
1400
- reg.findAllMatchIn(names.get.showDcl)
1401
- .map(_.group(1 ))
1402
- .zipWithIndex
1403
- .toMap
1404
- // TODO: The test should actually be: is unapplyFn generated by the compiler because we have a case class?
1405
- else if unapplyFn.tpe.widen.paramInfoss.head.head.typeSymbol.is(CaseClass ) then
1406
- unapplyFn.tpe.widen.paramInfoss.head.head.fields.map(_.name.toString).zipWithIndex.toMap
1407
- else
1408
- // TODO: Report member
1409
- report.error(" Doesn't support named patterns" )
1410
- Map .empty
1411
1412
// TODO: Is is necessary to convert names to strings?
1412
- .compose{ case name : Name => name .show }
1413
+ positionOfStringNames .compose(_ .show)
1413
1414
1414
1415
val namedArgs = bunchedArgs
1415
1416
.flatMap {
1416
1417
case pattern @ NamedArg (positionOfName(_), _) => Seq (pattern)
1417
1418
case pattern @ NamedArg (unknownName, _) =>
1418
- report.error(s " ' ${unknownName.show}' is unknown " , pattern)
1419
+ if (positionOfStringNames.nonEmpty)
1420
+ report.error(s " ' ${unknownName.show}' is unknown " , pattern)
1419
1421
Seq .empty
1420
1422
case unnamedArgument =>
1421
1423
report.error(" Only named arguments allowed here" , unnamedArgument)
0 commit comments