From 968bee3b189533e5242e4b1a36a499fbb45a97b8 Mon Sep 17 00:00:00 2001 From: Andrew Zurn Date: Thu, 27 Oct 2016 12:36:31 -0700 Subject: Add error message - _* syntax - Parsers.scala:1082 --- src/dotty/tools/dotc/parsing/Parsers.scala | 3 ++- .../tools/dotc/reporting/diagnostic/messages.scala | 27 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 95626846d..8768466a2 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1079,7 +1079,8 @@ object Parsers { if (in.token != RPAREN) syntaxError("`_*' can be used only for last argument", uscoreStart) Typed(t, atPos(uscoreStart) { Ident(tpnme.WILDCARD_STAR) }) } else { - syntaxErrorOrIncomplete("`*' expected"); t + syntaxErrorOrIncomplete(IncorrectRepeatedParameterSyntax()) + t } case AT if location != Location.InPattern => (t /: annotations())(Annotated) diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 69f5b52fe..b986b3cc8 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -580,7 +580,6 @@ object messages { } } - case class ByNameParameterNotSupported()(implicit ctx: Context) extends Message(21) { val kind = "Syntax" @@ -729,4 +728,30 @@ object messages { | - auxiliary constructors specify the implicit value |""" } + + case class IncorrectRepeatedParameterSyntax()(implicit ctx: Context) extends Message(27) { + val kind = "Syntax" + val msg = "'*' expected" + val explanation = + hl"""|Expected * in '_*' operator. + | + |The '_*' operator can be used to supply a sequence-based argument + |to a method with a variable-length or repeated parameter. It is used + |to expand the sequence to a variable number of arguments, such that: + |func(args: _*) would expand to func(arg1, arg2 ... argN). + | + |Below is an example of how a method with a variable-length + |parameter can be declared and used. + | + |Squares the arguments of a variable-length parameter: + |${"def square(args: Int*) = args.map(a => a * a)"} + | + |Usage: + |${"square(1, 2, 3) // res0: List[Int] = List(1, 4, 9)"} + | + |Secondary Usage with '_*': + |${"val ints = List(2, 3, 4) // ints: List[Int] = List(2, 3, 4)"} + |${"square(ints: _*) // res1: List[Int] = List(4, 9, 16)"} + |""".stripMargin + } } -- cgit v1.2.3