aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMiron Aseev <aseev.miron@gmail.com>2016-11-11 02:44:51 +0700
committerMiron Aseev <aseev.miron@gmail.com>2016-11-14 19:21:34 +0700
commit759dcf3f903a75fccfcb9e5039e537f8f08a4858 (patch)
treefcab9a040499e1d952c5a6212c8e90be164c96b8 /src
parent816fbd0d4cf6cefc93e02e4cf5bd067c517eea48 (diff)
downloaddotty-759dcf3f903a75fccfcb9e5039e537f8f08a4858.tar.gz
dotty-759dcf3f903a75fccfcb9e5039e537f8f08a4858.tar.bz2
dotty-759dcf3f903a75fccfcb9e5039e537f8f08a4858.zip
Add an error message for incorrect sequence wildcard pattern position
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala4
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala23
2 files changed, 25 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index ef4c970c6..717faa849 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -1076,7 +1076,7 @@ object Parsers {
val uscoreStart = in.skipToken()
if (isIdent(nme.raw.STAR)) {
in.nextToken()
- if (in.token != RPAREN) syntaxError("`_*' can be used only for last argument", uscoreStart)
+ if (in.token != RPAREN) syntaxError(SeqWildcardPatternPos(), uscoreStart)
Typed(t, atPos(uscoreStart) { Ident(tpnme.WILDCARD_STAR) })
} else {
syntaxErrorOrIncomplete(IncorrectRepeatedParameterSyntax())
@@ -1424,7 +1424,7 @@ object Parsers {
// `x: _*' is parsed in `ascription'
if (isIdent(nme.raw.STAR)) {
in.nextToken()
- if (in.token != RPAREN) syntaxError("`_*' can be used only for last argument", wildIndent.pos)
+ if (in.token != RPAREN) syntaxError(SeqWildcardPatternPos(), wildIndent.pos)
atPos(wildIndent.pos) { Ident(tpnme.WILDCARD_STAR) }
} else wildIndent
case LPAREN =>
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index 4ee27c852..e8f2ab8b7 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -789,4 +789,27 @@ object messages {
val msg = "unreachable code"
val explanation = ""
}
+
+ case class SeqWildcardPatternPos()(implicit ctx: Context) extends Message(31) {
+ val kind = "Syntax"
+ val msg = "`_*' can be used only for last argument"
+ val explanation = {
+ val code =
+ """def sumOfTheFirstTwo(list: List[Int]): Int = list match {
+ | case List(first, second, x:_*) => first + second
+ | case _ => 0
+ |}"""
+ hl"""|Sequence wildcard pattern is expected at the end of an argument list.
+ |This pattern matches any remaining elements in a sequence.
+ |Consider the following example:
+ |
+ |$code
+ |
+ |Calling:
+ |
+ |${"sumOfTheFirstTwo(List(1, 2, 10))"}
+ |
+ |would give 3 as a result"""
+ }
+ }
}