File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -1076,7 +1076,7 @@ object Parsers {
1076
1076
val uscoreStart = in.skipToken()
1077
1077
if (isIdent(nme.raw.STAR )) {
1078
1078
in.nextToken()
1079
- if (in.token != RPAREN ) syntaxError(" `_*' can be used only for last argument " , uscoreStart)
1079
+ if (in.token != RPAREN ) syntaxError(SeqWildcardPatternPos () , uscoreStart)
1080
1080
Typed (t, atPos(uscoreStart) { Ident (tpnme.WILDCARD_STAR ) })
1081
1081
} else {
1082
1082
syntaxErrorOrIncomplete(IncorrectRepeatedParameterSyntax ())
@@ -1424,7 +1424,7 @@ object Parsers {
1424
1424
// `x: _*' is parsed in `ascription'
1425
1425
if (isIdent(nme.raw.STAR )) {
1426
1426
in.nextToken()
1427
- if (in.token != RPAREN ) syntaxError(" `_*' can be used only for last argument " , wildIndent.pos)
1427
+ if (in.token != RPAREN ) syntaxError(SeqWildcardPatternPos () , wildIndent.pos)
1428
1428
atPos(wildIndent.pos) { Ident (tpnme.WILDCARD_STAR ) }
1429
1429
} else wildIndent
1430
1430
case LPAREN =>
Original file line number Diff line number Diff line change @@ -789,4 +789,27 @@ object messages {
789
789
val msg = " unreachable code"
790
790
val explanation = " "
791
791
}
792
+
793
+ case class SeqWildcardPatternPos ()(implicit ctx : Context ) extends Message (31 ) {
794
+ val kind = " Syntax"
795
+ val msg = " `_*' can be used only for last argument"
796
+ val explanation = {
797
+ val code =
798
+ """ def sumOfTheFirstTwo(list: List[Int]): Int = list match {
799
+ | case List(first, second, x:_*) => first + second
800
+ | case _ => 0
801
+ |}"""
802
+ hl """ |Sequence wildcard pattern is expected at the end of an argument list.
803
+ |This pattern matches any remaining elements in a sequence.
804
+ |Consider the following example:
805
+ |
806
+ | $code
807
+ |
808
+ |Calling:
809
+ |
810
+ | ${" sumOfTheFirstTwo(List(1, 2, 10))" }
811
+ |
812
+ |would give 3 as a result """
813
+ }
814
+ }
792
815
}
You can’t perform that action at this time.
0 commit comments