aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-03-18 17:28:47 +0100
committerodersky <odersky@gmail.com>2016-03-18 17:28:47 +0100
commit1b29119b8ed1a2c3b382dfca01d6dde71f6ae733 (patch)
treef4ae237bfee63c57131bd6a53760c10d6acbe8ea /src
parentf8ebf777b92e858a7ff8cfdf022e151b4f056920 (diff)
parent72b44d9b5df579e90b5aba5c55d04f6b34081d02 (diff)
downloaddotty-1b29119b8ed1a2c3b382dfca01d6dde71f6ae733.tar.gz
dotty-1b29119b8ed1a2c3b382dfca01d6dde71f6ae733.tar.bz2
dotty-1b29119b8ed1a2c3b382dfca01d6dde71f6ae733.zip
Merge pull request #1179 from liufengyun/fix-issue-1059
support `xs @ _*` and `_*` in Scala2 mode
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index 6ec75a8b2..ea9da8db9 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -259,11 +259,19 @@ object Parsers {
} finally inFunReturnType = saved
}
+ private val isScala2Mode =
+ ctx.settings.language.value.contains(nme.Scala2.toString)
+
+ def migrationWarningOrError(msg: String, offset: Int = in.offset) =
+ if (isScala2Mode)
+ ctx.migrationWarning(msg, source atPos Position(offset))
+ else
+ syntaxError(msg, offset)
+
/** Cannot use ctx.featureEnabled because accessing the context would force too much */
private def testScala2Mode(msg: String, pos: Position = Position(in.offset)) = {
- val s2 = ctx.settings.language.value.contains(nme.Scala2.toString)
- if (s2) ctx.migrationWarning(msg, source atPos pos)
- s2
+ if (isScala2Mode) ctx.migrationWarning(msg, source atPos pos)
+ isScala2Mode
}
/* ---------- TREE CONSTRUCTION ------------------------------------------- */
@@ -1309,7 +1317,20 @@ object Parsers {
*/
val pattern2 = () => infixPattern() match {
case p @ Ident(name) if isVarPattern(p) && in.token == AT =>
- atPos(p.pos.start, in.skipToken()) { Bind(name, infixPattern()) }
+ val pos = in.skipToken()
+
+ // compatibility for Scala2 `x @ _*` syntax
+ infixPattern() match {
+ case pt @ Ident(tpnme.WILDCARD_STAR) =>
+ migrationWarningOrError("The syntax `x @ _*' is no longer supported; use `x : _*' instead", p.pos.start)
+ atPos(p.pos.start, pos) { Typed(p, pt) }
+ case p =>
+ atPos(p.pos.start, pos) { Bind(name, p) }
+ }
+ case p @ Ident(tpnme.WILDCARD_STAR) =>
+ // compatibility for Scala2 `_*` syntax
+ migrationWarningOrError("The syntax `_*' is no longer supported; use `x : _*' instead", p.pos.start)
+ atPos(p.pos.start) { Typed(Ident(nme.WILDCARD), p) }
case p =>
p
}
@@ -1337,7 +1358,15 @@ object Parsers {
case t => simplePatternRest(t)
}
case USCORE =>
- wildcardIdent()
+ val wildIndent = wildcardIdent()
+
+ // compatibility for Scala2 `x @ _*` and `_*` syntax
+ // `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)
+ atPos(wildIndent.pos) { Ident(tpnme.WILDCARD_STAR) }
+ } else wildIndent
case LPAREN =>
atPos(in.offset) { makeTupleOrParens(inParens(patternsOpt())) }
case LBRACE =>