aboutsummaryrefslogtreecommitdiff
path: root/src/dotty
diff options
context:
space:
mode:
authorAndrew Zurn <awzurn@gmail.com>2016-10-27 12:36:31 -0700
committerAndrew Zurn <awzurn@gmail.com>2016-11-02 20:37:24 -0700
commit968bee3b189533e5242e4b1a36a499fbb45a97b8 (patch)
tree25a423ad726d7ed7a2ba83b9930ad184fc01411d /src/dotty
parent0de379797ebcb84683e51640d1c6f11870be988f (diff)
downloaddotty-968bee3b189533e5242e4b1a36a499fbb45a97b8.tar.gz
dotty-968bee3b189533e5242e4b1a36a499fbb45a97b8.tar.bz2
dotty-968bee3b189533e5242e4b1a36a499fbb45a97b8.zip
Add error message - _* syntax - Parsers.scala:1082
Diffstat (limited to 'src/dotty')
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala3
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala27
2 files changed, 28 insertions, 2 deletions
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
+ }
}