@@ -1200,14 +1200,15 @@ object Parsers {
1200
1200
* | ForExpr
1201
1201
* | [SimpleExpr `.'] id `=' Expr
1202
1202
* | SimpleExpr1 ArgumentExprs `=' Expr
1203
- * | PostfixExpr [Ascription]
1204
- * | [‘inline’] PostfixExpr `match' `{' CaseClauses `}'
1203
+ * | Expr2
1204
+ * | [‘inline’] Expr2 `match' `{' CaseClauses `}'
1205
1205
* | `implicit' `match' `{' ImplicitCaseClauses `}'
1206
- * Bindings ::= `(' [Binding {`,' Binding}] `)'
1207
- * Binding ::= (id | `_') [`:' Type]
1208
- * Ascription ::= `:' CompoundType
1209
- * | `:' Annotation {Annotation}
1210
- * | `:' `_' `*'
1206
+ * Bindings ::= `(' [Binding {`,' Binding}] `)'
1207
+ * Binding ::= (id | `_') [`:' Type]
1208
+ * Expr2 ::= PostfixExpr [Ascription]
1209
+ * Ascription ::= `:' InfixType
1210
+ * | `:' Annotation {Annotation}
1211
+ * | `:' `_' `*'
1211
1212
*/
1212
1213
val exprInParens : () => Tree = () => expr(Location .InParens )
1213
1214
@@ -1324,15 +1325,16 @@ object Parsers {
1324
1325
t
1325
1326
}
1326
1327
case COLON =>
1327
- ascription(t, location)
1328
+ in.nextToken()
1329
+ val t1 = ascription(t, location)
1330
+ if (in.token == MATCH ) expr1Rest(t1, location) else t1
1328
1331
case MATCH =>
1329
1332
matchExpr(t, startOffset(t), Match )
1330
1333
case _ =>
1331
1334
t
1332
1335
}
1333
1336
1334
1337
def ascription (t : Tree , location : Location .Value ): Tree = atSpan(startOffset(t)) {
1335
- in.skipToken()
1336
1338
in.token match {
1337
1339
case USCORE =>
1338
1340
val uscoreStart = in.skipToken()
@@ -1801,7 +1803,10 @@ object Parsers {
1801
1803
*/
1802
1804
def pattern1 (): Tree = {
1803
1805
val p = pattern2()
1804
- if (isVarPattern(p) && in.token == COLON ) ascription(p, Location .InPattern )
1806
+ if (isVarPattern(p) && in.token == COLON ) {
1807
+ in.nextToken()
1808
+ ascription(p, Location .InPattern )
1809
+ }
1805
1810
else p
1806
1811
}
1807
1812
@@ -2353,14 +2358,32 @@ object Parsers {
2353
2358
tmplDef(start, mods)
2354
2359
}
2355
2360
2356
- /** PatDef ::= Pattern2 {`,' Pattern2} [`:' Type] `=' Expr
2357
- * VarDef ::= PatDef | id {`,' id} `:' Type `=' `_'
2358
- * ValDcl ::= id {`,' id} `:' Type
2359
- * VarDcl ::= id {`,' id} `:' Type
2361
+ /** PatDef ::= ids [‘:’ Type] ‘=’ Expr
2362
+ * | Pattern2 [‘:’ Type | Ascription] ‘=’ Expr
2363
+ * VarDef ::= PatDef | id {`,' id} `:' Type `=' `_'
2364
+ * ValDcl ::= id {`,' id} `:' Type
2365
+ * VarDcl ::= id {`,' id} `:' Type
2360
2366
*/
2361
2367
def patDefOrDcl (start : Offset , mods : Modifiers ): Tree = atSpan(start, nameStart) {
2362
- val lhs = commaSeparated(pattern2)
2363
- val tpt = typedOpt()
2368
+ val first = pattern2()
2369
+ var lhs = first match {
2370
+ case id : Ident if in.token == COMMA =>
2371
+ in.nextToken()
2372
+ id :: commaSeparated(() => termIdent())
2373
+ case _ =>
2374
+ first :: Nil
2375
+ }
2376
+ def emptyType = TypeTree ().withSpan(Span (in.lastOffset))
2377
+ val tpt =
2378
+ if (in.token == COLON ) {
2379
+ in.nextToken()
2380
+ if (in.token == AT && lhs.tail.isEmpty) {
2381
+ lhs = ascription(first, Location .ElseWhere ) :: Nil
2382
+ emptyType
2383
+ }
2384
+ else toplevelTyp()
2385
+ }
2386
+ else emptyType
2364
2387
val rhs =
2365
2388
if (tpt.isEmpty || in.token == EQUALS ) {
2366
2389
accept(EQUALS )
@@ -2374,9 +2397,9 @@ object Parsers {
2374
2397
lhs match {
2375
2398
case (id : BackquotedIdent ) :: Nil if id.name.isTermName =>
2376
2399
finalizeDef(BackquotedValDef (id.name.asTermName, tpt, rhs), mods, start)
2377
- case Ident (name : TermName ) :: Nil => {
2400
+ case Ident (name : TermName ) :: Nil =>
2378
2401
finalizeDef(ValDef (name, tpt, rhs), mods, start)
2379
- } case _ =>
2402
+ case _ =>
2380
2403
PatDef (mods, lhs, tpt, rhs)
2381
2404
}
2382
2405
}
0 commit comments