@@ -352,15 +352,15 @@ object Parsers {
352352
353353 /** Convert tree to formal parameter list
354354 */
355- def convertToParams (tree : Tree ): List [ValDef ] = tree match {
356- case Parens (t) => convertToParam(t) :: Nil
357- case Tuple (ts) => ts map (convertToParam(_))
358- case t => convertToParam(t) :: Nil
355+ def convertToParams (tree : Tree , mods : Modifiers ): List [ValDef ] = tree match {
356+ case Parens (t) => convertToParam(t, mods ) :: Nil
357+ case Tuple (ts) => ts map (convertToParam(_, mods ))
358+ case t => convertToParam(t, mods ) :: Nil
359359 }
360360
361361 /** Convert tree to formal parameter
362362 */
363- def convertToParam (tree : Tree , mods : Modifiers = Modifiers () , expected : String = " formal parameter" ): ValDef = tree match {
363+ def convertToParam (tree : Tree , mods : Modifiers , expected : String = " formal parameter" ): ValDef = tree match {
364364 case Ident (name) =>
365365 makeParameter(name.asTermName, TypeTree (), mods) withPos tree.pos
366366 case Typed (Ident (name), tpt) =>
@@ -754,7 +754,7 @@ object Parsers {
754754 */
755755 def toplevelTyp (): Tree = checkWildcard(typ())
756756
757- /** Type ::= [FunArgMods ] FunArgTypes `=>' Type
757+ /** Type ::= [‘erased’ ] FunArgTypes (‘=>’ | ‘|=>’) Type
758758 * | HkTypeParamClause `->' Type
759759 * | InfixType
760760 * FunArgTypes ::= InfixType
@@ -763,11 +763,20 @@ object Parsers {
763763 */
764764 def typ (): Tree = {
765765 val start = in.offset
766- val imods = modifiers(funArgMods )
766+ val imods = modifiers(BitSet ( ERASED ) )
767767 def functionRest (params : List [Tree ]): Tree =
768- atPos(start, accept(ARROW )) {
768+ atPos(start, in.offset) {
769+ val pmods =
770+ if (in.token == CARROW ) {
771+ in.nextToken()
772+ imods | (Contextual | Implicit )
773+ }
774+ else {
775+ accept(ARROW )
776+ imods
777+ }
769778 val t = typ()
770- if (imods. is(Implicit ) || imods.is( Erased )) new FunctionWithMods (params, t, imods )
779+ if (pmods.flags. is(Implicit | Contextual | Erased )) new FunctionWithMods (params, t, pmods )
771780 else Function (params, t)
772781 }
773782 def funArgTypesRest (first : Tree , following : () => Tree ) = {
@@ -801,7 +810,8 @@ object Parsers {
801810 }
802811 openParens.change(LPAREN , - 1 )
803812 accept(RPAREN )
804- if (imods.is(Implicit ) || isValParamList || in.token == ARROW ) functionRest(ts)
813+ if (imods.is(Implicit ) || isValParamList || in.token == ARROW || in.token == CARROW )
814+ functionRest(ts)
805815 else {
806816 val ts1 =
807817 for (t <- ts) yield {
@@ -832,7 +842,7 @@ object Parsers {
832842 else infixType()
833843
834844 in.token match {
835- case ARROW => functionRest(t :: Nil )
845+ case ARROW | CARROW => functionRest(t :: Nil )
836846 case MATCH => matchType(EmptyTree , t)
837847 case FORSOME => syntaxError(ExistentialTypesNoLongerSupported ()); t
838848 case _ =>
@@ -1109,6 +1119,7 @@ object Parsers {
11091119 }
11101120
11111121 /** Expr ::= [FunArgMods] FunParams =>' Expr
1122+ * | [‘erased’] FunParams ‘|=>’ Expr
11121123 * | Expr1
11131124 * FunParams ::= Bindings
11141125 * | id
@@ -1157,9 +1168,11 @@ object Parsers {
11571168 finally placeholderParams = saved
11581169
11591170 val t = expr1(location)
1160- if (in.token == ARROW ) {
1171+ if (in.token == ARROW || in.token == CARROW ) {
11611172 placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder
1162- wrapPlaceholders(closureRest(start, location, convertToParams(t)))
1173+ val impliedMods =
1174+ if (in.token == CARROW ) Modifiers (Implicit | Contextual ) else EmptyModifiers
1175+ wrapPlaceholders(closureRest(start, location, convertToParams(t, impliedMods)))
11631176 }
11641177 else if (isWildcard(t)) {
11651178 placeholderParams = placeholderParams ::: saved
@@ -1340,16 +1353,28 @@ object Parsers {
13401353 }
13411354 else ident()
13421355
1343- /** Expr ::= implicit id `=>' Expr
1356+ /** Expr ::= FunArgMods FunParams `=>' Expr
1357+ * | [‘erased’] FunParams ‘|=>’ Expr
13441358 * BlockResult ::= implicit id [`:' InfixType] `=>' Block // Scala2 only
13451359 */
13461360 def implicitClosure (start : Int , location : Location .Value , implicitMods : Modifiers ): Tree =
13471361 closureRest(start, location, funParams(implicitMods, location))
13481362
13491363 def closureRest (start : Int , location : Location .Value , params : List [Tree ]): Tree =
13501364 atPos(start, in.offset) {
1351- accept(ARROW )
1352- Function (params, if (location == Location .InBlock ) block() else expr())
1365+ val params1 =
1366+ if (in.token == CARROW ) {
1367+ in.nextToken()
1368+ params.map {
1369+ case param : ValDef => param.withMods(param.mods | (Implicit | Contextual ))
1370+ case param => param
1371+ }
1372+ }
1373+ else {
1374+ accept(ARROW )
1375+ params
1376+ }
1377+ Function (params1, if (location == Location .InBlock ) block() else expr())
13531378 }
13541379
13551380 /** PostfixExpr ::= InfixExpr [id [nl]]
@@ -2622,7 +2647,7 @@ object Parsers {
26222647 case Typed (tree @ This (EmptyTypeIdent ), tpt) =>
26232648 self = makeSelfDef(nme.WILDCARD , tpt).withPos(first.pos)
26242649 case _ =>
2625- val ValDef (name, tpt, _) = convertToParam(first, expected = " self type clause" )
2650+ val ValDef (name, tpt, _) = convertToParam(first, EmptyModifiers , " self type clause" )
26262651 if (name != nme.ERROR )
26272652 self = makeSelfDef(name, tpt).withPos(first.pos)
26282653 }
0 commit comments