@@ -443,35 +443,35 @@ object Parsers {
443443
444444 /** Convert tree to formal parameter list
445445 */
446- def convertToParams (tree : Tree ): List [ValDef ] = tree match {
446+ def convertToParams (tree : Tree , mods : Modifiers ): List [ValDef ] = tree match {
447447 case Parens (t) =>
448- convertToParam(t) :: Nil
448+ convertToParam(t, mods ) :: Nil
449449 case Tuple (ts) =>
450- ts.map(convertToParam(_))
450+ ts.map(convertToParam(_, mods ))
451451 case t : Typed =>
452452 report.errorOrMigrationWarning(
453453 em " parentheses are required around the parameter of a lambda ${rewriteNotice()}" ,
454454 in.sourcePos())
455455 if migrateTo3 then
456456 patch(source, t.span.startPos, " (" )
457457 patch(source, t.span.endPos, " )" )
458- convertToParam(t) :: Nil
458+ convertToParam(t, mods ) :: Nil
459459 case t =>
460- convertToParam(t) :: Nil
460+ convertToParam(t, mods ) :: Nil
461461 }
462462
463463 /** Convert tree to formal parameter
464464 */
465- def convertToParam (tree : Tree , expected : String = " formal parameter" ): ValDef = tree match {
465+ def convertToParam (tree : Tree , mods : Modifiers , expected : String = " formal parameter" ): ValDef = tree match {
466466 case id @ Ident (name) =>
467- makeParameter(name.asTermName, TypeTree (), EmptyModifiers , isBackquoted = isBackquoted(id)).withSpan(tree.span)
467+ makeParameter(name.asTermName, TypeTree (), mods , isBackquoted = isBackquoted(id)).withSpan(tree.span)
468468 case Typed (id @ Ident (name), tpt) =>
469- makeParameter(name.asTermName, tpt, EmptyModifiers , isBackquoted = isBackquoted(id)).withSpan(tree.span)
469+ makeParameter(name.asTermName, tpt, mods , isBackquoted = isBackquoted(id)).withSpan(tree.span)
470470 case Typed (Splice (Ident (name)), tpt) =>
471- makeParameter((" $" + name).toTermName, tpt, EmptyModifiers ).withSpan(tree.span)
471+ makeParameter((" $" + name).toTermName, tpt, mods ).withSpan(tree.span)
472472 case _ =>
473473 syntaxError(s " not a legal $expected" , tree.span)
474- makeParameter(nme.ERROR , tree, EmptyModifiers )
474+ makeParameter(nme.ERROR , tree, mods )
475475 }
476476
477477 /** Convert (qual)ident to type identifier
@@ -1864,14 +1864,14 @@ object Parsers {
18641864 accept(altToken)
18651865 t
18661866
1867- /** Expr ::= [`implicit'] FunParams ‘=>’ Expr
1867+ /** Expr ::= [`implicit'] FunParams ( ‘=>’ | ‘?=>’) Expr
18681868 * | Expr1
18691869 * FunParams ::= Bindings
18701870 * | id
18711871 * | `_'
18721872 * ExprInParens ::= PostfixExpr `:' Type
18731873 * | Expr
1874- * BlockResult ::= [‘implicit’] FunParams ‘=>’ Block
1874+ * BlockResult ::= [‘implicit’] FunParams ( ‘=>’ | ‘?=>’) Block
18751875 * | Expr1
18761876 * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
18771877 * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -1920,9 +1920,10 @@ object Parsers {
19201920 finally placeholderParams = saved
19211921
19221922 val t = expr1(location)
1923- if (in.token == ARROW ) {
1923+ if (in.token == ARROW || in.token == CTXARROW ) {
19241924 placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder
1925- wrapPlaceholders(closureRest(start, location, convertToParams(t)))
1925+ val paramMods = if in.token == CTXARROW then Modifiers (Given ) else EmptyModifiers
1926+ wrapPlaceholders(closureRest(start, location, convertToParams(t, paramMods)))
19261927 }
19271928 else if (isWildcard(t)) {
19281929 placeholderParams = placeholderParams ::: saved
@@ -2124,7 +2125,7 @@ object Parsers {
21242125 /** FunParams ::= Bindings
21252126 * | id
21262127 * | `_'
2127- * Bindings ::= `(' [[‘using’] [‘ erased’] Binding {`,' Binding}] `)'
2128+ * Bindings ::= `(' [[‘erased’] Binding {`,' Binding}] `)'
21282129 */
21292130 def funParams (mods : Modifiers , location : Location ): List [Tree ] =
21302131 if in.token == LPAREN then
@@ -2185,7 +2186,7 @@ object Parsers {
21852186
21862187 def closureRest (start : Int , location : Location , params : List [Tree ]): Tree =
21872188 atSpan(start, in.offset) {
2188- accept(ARROW )
2189+ if in.token == CTXARROW then in.nextToken() else accept(ARROW )
21892190 Function (params, if (location == Location .InBlock ) block() else expr())
21902191 }
21912192
@@ -2309,7 +2310,7 @@ object Parsers {
23092310 possibleTemplateStart()
23102311 val parents =
23112312 if in.isNestedStart then Nil
2312- else constrApps(commaOK = false , templateCanFollow = true )
2313+ else constrApps(commaOK = false )
23132314 colonAtEOLOpt()
23142315 possibleTemplateStart(isNew = true )
23152316 parents match {
@@ -3492,7 +3493,7 @@ object Parsers {
34923493 val parents =
34933494 if (in.token == EXTENDS ) {
34943495 in.nextToken()
3495- constrApps(commaOK = true , templateCanFollow = false )
3496+ constrApps(commaOK = true )
34963497 }
34973498 else Nil
34983499 Template (constr, parents, Nil , EmptyValDef , Nil )
@@ -3536,7 +3537,7 @@ object Parsers {
35363537 val noParams = tparams.isEmpty && vparamss.isEmpty
35373538 if ! (name.isEmpty && noParams) then
35383539 accept(nme.as)
3539- val parents = constrApps(commaOK = true , templateCanFollow = true )
3540+ val parents = constrApps(commaOK = true )
35403541 if in.token == EQUALS && parents.length == 1 && parents.head.isType then
35413542 accept(EQUALS )
35423543 mods1 |= Final
@@ -3616,19 +3617,12 @@ object Parsers {
36163617
36173618 /** ConstrApps ::= ConstrApp {(‘,’ | ‘with’) ConstrApp}
36183619 */
3619- def constrApps (commaOK : Boolean , templateCanFollow : Boolean ): List [Tree ] =
3620+ def constrApps (commaOK : Boolean ): List [Tree ] =
36203621 val t = constrApp()
36213622 val ts =
3622- if in.token == WITH then
3623- in.nextToken()
3624- newLineOptWhenFollowedBy(LBRACE )
3625- if templateCanFollow && (in.token == LBRACE || in.token == INDENT ) then
3626- Nil
3627- else
3628- constrApps(commaOK, templateCanFollow)
3629- else if commaOK && in.token == COMMA then
3623+ if in.token == WITH || commaOK && in.token == COMMA then
36303624 in.nextToken()
3631- constrApps(commaOK, templateCanFollow )
3625+ constrApps(commaOK)
36323626 else Nil
36333627 t :: ts
36343628
@@ -3645,7 +3639,7 @@ object Parsers {
36453639 in.sourcePos())
36463640 Nil
36473641 }
3648- else constrApps(commaOK = true , templateCanFollow = true )
3642+ else constrApps(commaOK = true )
36493643 }
36503644 else Nil
36513645 newLinesOptWhenFollowedBy(nme.derives )
@@ -3772,7 +3766,7 @@ object Parsers {
37723766 case Typed (tree @ This (EmptyTypeIdent ), tpt) =>
37733767 self = makeSelfDef(nme.WILDCARD , tpt).withSpan(first.span)
37743768 case _ =>
3775- val ValDef (name, tpt, _) = convertToParam(first, " self type clause" )
3769+ val ValDef (name, tpt, _) = convertToParam(first, EmptyModifiers , " self type clause" )
37763770 if (name != nme.ERROR )
37773771 self = makeSelfDef(name, tpt).withSpan(first.span)
37783772 }
0 commit comments