@@ -259,11 +259,19 @@ object Parsers {
259
259
} finally inFunReturnType = saved
260
260
}
261
261
262
+ private val isScala2Mode =
263
+ ctx.settings.language.value.contains(nme.Scala2 .toString)
264
+
265
+ def migrationWarningOrError (msg : String , offset : Int = in.offset) =
266
+ if (isScala2Mode)
267
+ ctx.migrationWarning(msg, source atPos Position (offset))
268
+ else
269
+ syntaxError(msg, offset)
270
+
262
271
/** Cannot use ctx.featureEnabled because accessing the context would force too much */
263
272
private def testScala2Mode (msg : String , pos : Position = Position (in.offset)) = {
264
- val s2 = ctx.settings.language.value.contains(nme.Scala2 .toString)
265
- if (s2) ctx.migrationWarning(msg, source atPos pos)
266
- s2
273
+ if (isScala2Mode) ctx.migrationWarning(msg, source atPos pos)
274
+ isScala2Mode
267
275
}
268
276
269
277
/* ---------- TREE CONSTRUCTION ------------------------------------------- */
@@ -1309,7 +1317,20 @@ object Parsers {
1309
1317
*/
1310
1318
val pattern2 = () => infixPattern() match {
1311
1319
case p @ Ident (name) if isVarPattern(p) && in.token == AT =>
1312
- atPos(p.pos.start, in.skipToken()) { Bind (name, infixPattern()) }
1320
+ val pos = in.skipToken()
1321
+
1322
+ // compatibility for Scala2 `x @ _*` syntax
1323
+ infixPattern() match {
1324
+ case pt @ Ident (tpnme.WILDCARD_STAR ) =>
1325
+ migrationWarningOrError(" The syntax `x @ _*' is no longer supported; use `x : _*' instead" , p.pos.start)
1326
+ atPos(p.pos.start, pos) { Typed (p, pt) }
1327
+ case p =>
1328
+ atPos(p.pos.start, pos) { Bind (name, p) }
1329
+ }
1330
+ case p @ Ident (tpnme.WILDCARD_STAR ) =>
1331
+ // compatibility for Scala2 `_*` syntax
1332
+ migrationWarningOrError(" The syntax `_*' is no longer supported; use `x : _*' instead" , p.pos.start)
1333
+ atPos(p.pos.start) { Typed (Ident (nme.WILDCARD ), p) }
1313
1334
case p =>
1314
1335
p
1315
1336
}
@@ -1337,7 +1358,15 @@ object Parsers {
1337
1358
case t => simplePatternRest(t)
1338
1359
}
1339
1360
case USCORE =>
1340
- wildcardIdent()
1361
+ val wildIndent = wildcardIdent()
1362
+
1363
+ // compatibility for Scala2 `x @ _*` and `_*` syntax
1364
+ // `x: _*' is parsed in `ascription'
1365
+ if (isIdent(nme.raw.STAR )) {
1366
+ in.nextToken()
1367
+ if (in.token != RPAREN ) syntaxError(" `_*' can be used only for last argument" , wildIndent.pos)
1368
+ atPos(wildIndent.pos) { Ident (tpnme.WILDCARD_STAR ) }
1369
+ } else wildIndent
1341
1370
case LPAREN =>
1342
1371
atPos(in.offset) { makeTupleOrParens(inParens(patternsOpt())) }
1343
1372
case LBRACE =>
0 commit comments