@@ -1325,6 +1325,7 @@ object Parsers {
13251325 t
13261326 }
13271327 case COLON =>
1328+ in.nextToken()
13281329 val t1 = ascription(t, location)
13291330 if (in.token == MATCH ) expr1Rest(t1, location) else t1
13301331 case MATCH =>
@@ -1334,7 +1335,6 @@ object Parsers {
13341335 }
13351336
13361337 def ascription (t : Tree , location : Location .Value ): Tree = atSpan(startOffset(t)) {
1337- in.skipToken()
13381338 in.token match {
13391339 case USCORE =>
13401340 val uscoreStart = in.skipToken()
@@ -1803,7 +1803,10 @@ object Parsers {
18031803 */
18041804 def pattern1 (): Tree = {
18051805 val p = pattern2()
1806- 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+ }
18071810 else p
18081811 }
18091812
@@ -2356,21 +2359,31 @@ object Parsers {
23562359 }
23572360
23582361 /** PatDef ::= ids [‘:’ Type] ‘=’ Expr
2359- * | Pattern2 [‘:’ Type] ‘=’ Expr
2362+ * | Pattern2 [‘:’ Type | Ascription ] ‘=’ Expr
23602363 * VarDef ::= PatDef | id {`,' id} `:' Type `=' `_'
23612364 * ValDcl ::= id {`,' id} `:' Type
23622365 * VarDcl ::= id {`,' id} `:' Type
23632366 */
23642367 def patDefOrDcl (start : Offset , mods : Modifiers ): Tree = atSpan(start, nameStart) {
23652368 val first = pattern2()
2366- val lhs = first match {
2369+ var lhs = first match {
23672370 case id : Ident if in.token == COMMA =>
23682371 in.nextToken()
23692372 id :: commaSeparated(() => termIdent())
23702373 case _ =>
23712374 first :: Nil
23722375 }
2373- val tpt = typedOpt()
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
23742387 val rhs =
23752388 if (tpt.isEmpty || in.token == EQUALS ) {
23762389 accept(EQUALS )
@@ -2384,9 +2397,9 @@ object Parsers {
23842397 lhs match {
23852398 case (id : BackquotedIdent ) :: Nil if id.name.isTermName =>
23862399 finalizeDef(BackquotedValDef (id.name.asTermName, tpt, rhs), mods, start)
2387- case Ident (name : TermName ) :: Nil => {
2400+ case Ident (name : TermName ) :: Nil =>
23882401 finalizeDef(ValDef (name, tpt, rhs), mods, start)
2389- } case _ =>
2402+ case _ =>
23902403 PatDef (mods, lhs, tpt, rhs)
23912404 }
23922405 }
0 commit comments