Skip to content

Add an error message for incorrect sequence wildcard position Parsers.scala:1425 and Parsers.scala:1079 #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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 =>
Expand Down
23 changes: 23 additions & 0 deletions src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
}
}
}