@@ -1838,13 +1838,15 @@ object Parsers {
18381838 t
18391839
18401840 /** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr
1841+ * | HkTypeParamClause ‘=>’ Expr
18411842 * | Expr1
18421843 * FunParams ::= Bindings
18431844 * | id
18441845 * | `_'
18451846 * ExprInParens ::= PostfixExpr `:' Type
18461847 * | Expr
18471848 * BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block
1849+ * | HkTypeParamClause ‘=>’ Block
18481850 * | Expr1
18491851 * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
18501852 * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -1855,7 +1857,6 @@ object Parsers {
18551857 * | `throw' Expr
18561858 * | `return' [Expr]
18571859 * | ForExpr
1858- * | HkTypeParamClause ‘=>’ Expr
18591860 * | [SimpleExpr `.'] id `=' Expr
18601861 * | SimpleExpr1 ArgumentExprs `=' Expr
18611862 * | PostfixExpr [Ascription]
@@ -1876,28 +1877,41 @@ object Parsers {
18761877 def expr (location : Location ): Tree = {
18771878 val start = in.offset
18781879 def isSpecialClosureStart = in.lookahead.isIdent(nme.erased) && in.erasedEnabled
1879- if in.token == IMPLICIT then
1880- closure(start, location, modifiers(BitSet (IMPLICIT )))
1881- else if in.token == LPAREN && isSpecialClosureStart then
1882- closure(start, location, Modifiers ())
1883- else {
1884- val saved = placeholderParams
1885- placeholderParams = Nil
1886-
1887- def wrapPlaceholders (t : Tree ) = try
1888- if (placeholderParams.isEmpty) t
1889- else new WildcardFunction (placeholderParams.reverse, t)
1890- finally placeholderParams = saved
1891-
1892- val t = expr1(location)
1893- if in.isArrow then
1894- placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder
1895- wrapPlaceholders(closureRest(start, location, convertToParams(t)))
1896- else if isWildcard(t) then
1897- placeholderParams = placeholderParams ::: saved
1898- t
1899- else wrapPlaceholders(t)
1900- }
1880+ in.token match
1881+ case IMPLICIT =>
1882+ closure(start, location, modifiers(BitSet (IMPLICIT )))
1883+ case LPAREN if isSpecialClosureStart =>
1884+ closure(start, location, Modifiers ())
1885+ case LBRACKET =>
1886+ val start = in.offset
1887+ val tparams = typeParamClause(ParamOwner .TypeParam )
1888+ val arrowOffset = accept(ARROW )
1889+ val body = expr(location)
1890+ atSpan(start, arrowOffset) {
1891+ if (isFunction(body))
1892+ PolyFunction (tparams, body)
1893+ else {
1894+ syntaxError(" Implementation restriction: polymorphic function literals must have a value parameter" , arrowOffset)
1895+ errorTermTree
1896+ }
1897+ }
1898+ case _ =>
1899+ val saved = placeholderParams
1900+ placeholderParams = Nil
1901+
1902+ def wrapPlaceholders (t : Tree ) = try
1903+ if (placeholderParams.isEmpty) t
1904+ else new WildcardFunction (placeholderParams.reverse, t)
1905+ finally placeholderParams = saved
1906+
1907+ val t = expr1(location)
1908+ if in.isArrow then
1909+ placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder
1910+ wrapPlaceholders(closureRest(start, location, convertToParams(t)))
1911+ else if isWildcard(t) then
1912+ placeholderParams = placeholderParams ::: saved
1913+ t
1914+ else wrapPlaceholders(t)
19011915 }
19021916
19031917 def expr1 (location : Location = Location .ElseWhere ): Tree = in.token match
@@ -1981,19 +1995,6 @@ object Parsers {
19811995 }
19821996 case FOR =>
19831997 forExpr()
1984- case LBRACKET =>
1985- val start = in.offset
1986- val tparams = typeParamClause(ParamOwner .TypeParam )
1987- val arrowOffset = accept(ARROW )
1988- val body = expr()
1989- atSpan(start, arrowOffset) {
1990- if (isFunction(body))
1991- PolyFunction (tparams, body)
1992- else {
1993- syntaxError(" Implementation restriction: polymorphic function literals must have a value parameter" , arrowOffset)
1994- errorTermTree
1995- }
1996- }
19971998 case _ =>
19981999 if isIdent(nme.inline)
19992000 && ! in.inModifierPosition()
0 commit comments