@@ -1200,14 +1200,15 @@ object Parsers {
12001200 * | ForExpr
12011201 * | [SimpleExpr `.'] id `=' Expr
12021202 * | SimpleExpr1 ArgumentExprs `=' Expr
1203- * | PostfixExpr [Ascription]
1204- * | [‘inline’] PostfixExpr `match' `{' CaseClauses `}'
1203+ * | Expr2
1204+ * | [‘inline’] Expr2 `match' `{' CaseClauses `}'
12051205 * | `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+ * | `:' `_' `*'
12111212 */
12121213 val exprInParens : () => Tree = () => expr(Location .InParens )
12131214
@@ -1324,15 +1325,16 @@ object Parsers {
13241325 t
13251326 }
13261327 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
13281331 case MATCH =>
13291332 matchExpr(t, startOffset(t), Match )
13301333 case _ =>
13311334 t
13321335 }
13331336
13341337 def ascription (t : Tree , location : Location .Value ): Tree = atSpan(startOffset(t)) {
1335- in.skipToken()
13361338 in.token match {
13371339 case USCORE =>
13381340 val uscoreStart = in.skipToken()
@@ -1801,7 +1803,10 @@ object Parsers {
18011803 */
18021804 def pattern1 (): Tree = {
18031805 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+ }
18051810 else p
18061811 }
18071812
@@ -2353,14 +2358,32 @@ object Parsers {
23532358 tmplDef(start, mods)
23542359 }
23552360
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
23602366 */
23612367 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
23642387 val rhs =
23652388 if (tpt.isEmpty || in.token == EQUALS ) {
23662389 accept(EQUALS )
@@ -2374,9 +2397,9 @@ object Parsers {
23742397 lhs match {
23752398 case (id : BackquotedIdent ) :: Nil if id.name.isTermName =>
23762399 finalizeDef(BackquotedValDef (id.name.asTermName, tpt, rhs), mods, start)
2377- case Ident (name : TermName ) :: Nil => {
2400+ case Ident (name : TermName ) :: Nil =>
23782401 finalizeDef(ValDef (name, tpt, rhs), mods, start)
2379- } case _ =>
2402+ case _ =>
23802403 PatDef (mods, lhs, tpt, rhs)
23812404 }
23822405 }
0 commit comments