@@ -2797,12 +2797,12 @@ object Parsers {
2797
2797
tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given ))
2798
2798
2799
2799
/** ClsParamClause ::= ‘(’ [‘erased’] ClsParams ‘)’
2800
- * GivenClsParamClause::= ‘(’ ‘given’ [‘erased’] (ClsParams | GivenTypes) ‘)’
2800
+ * GivenClsParamClause::= 'with' ‘(’ (ClsParams | GivenTypes) ‘)’
2801
2801
* ClsParams ::= ClsParam {‘,’ ClsParam}
2802
2802
* ClsParam ::= {Annotation}
2803
2803
*
2804
2804
* DefParamClause ::= ‘(’ [‘erased’] DefParams ‘)’
2805
- * GivenParamClause ::= ‘( ’ ‘given’ [‘erased’] (DefParams | GivenTypes) ‘)’
2805
+ * GivenParamClause ::= ‘with ’ ‘(’ (DefParams | GivenTypes) ‘)’
2806
2806
* DefParams ::= DefParam {‘,’ DefParam}
2807
2807
* DefParam ::= {Annotation} [‘inline’] Param
2808
2808
*
@@ -2815,9 +2815,10 @@ object Parsers {
2815
2815
ofCaseClass : Boolean = false , // owner is a case class
2816
2816
prefix : Boolean = false , // clause precedes name of an extension method
2817
2817
givenOnly : Boolean = false , // only given parameters allowed
2818
- firstClause : Boolean = false // clause is the first in regular list of clauses
2818
+ firstClause : Boolean = false , // clause is the first in regular list of clauses
2819
+ prefixMods : Modifiers = EmptyModifiers // is `Given` if this is a with clause
2819
2820
): List [ValDef ] = {
2820
- var impliedMods : Modifiers = EmptyModifiers
2821
+ var impliedMods : Modifiers = prefixMods
2821
2822
2822
2823
def impliedModOpt (token : Token , mod : () => Mod ): Boolean =
2823
2824
if in.token == token then
@@ -2900,9 +2901,10 @@ object Parsers {
2900
2901
}
2901
2902
2902
2903
/** ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
2903
- * | {ClsParamClause} { GivenClsParamClause}
2904
+ * | {ClsParamClause | GivenClsParamClause} [‘with’ GivenTypes]
2904
2905
* DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
2905
- * | {DefParamClause} {GivenParamClause}
2906
+ * | {DefParamClause | GivenParamClause} [‘with’ GivenTypes]
2907
+ * GivenParamClauses ::= {GivenParamClause} [‘with’ GivenTypes]
2906
2908
*
2907
2909
* @return The parameter definitions
2908
2910
*/
@@ -2912,18 +2914,27 @@ object Parsers {
2912
2914
2913
2915
def recur (firstClause : Boolean , nparams : Int ): List [List [ValDef ]] =
2914
2916
newLineOptWhenFollowedBy(LPAREN )
2917
+ val prefixMods =
2918
+ if in.token == WITH then
2919
+ in.nextToken()
2920
+ Modifiers (Given )
2921
+ else
2922
+ EmptyModifiers
2915
2923
if in.token == LPAREN then
2916
2924
val paramsStart = in.offset
2917
2925
val params = paramClause(
2918
2926
nparams,
2919
2927
ofClass = ofClass,
2920
2928
ofCaseClass = ofCaseClass,
2921
2929
givenOnly = givenOnly,
2922
- firstClause = firstClause)
2930
+ firstClause = firstClause,
2931
+ prefixMods = prefixMods)
2923
2932
val lastClause = params.nonEmpty && params.head.mods.flags.is(Implicit )
2924
2933
params :: (
2925
2934
if lastClause then Nil
2926
2935
else recur(firstClause = false , nparams + params.length))
2936
+ else if prefixMods.is(Given ) then
2937
+ givenTypes(nparams, ofClass) :: Nil
2927
2938
else Nil
2928
2939
end recur
2929
2940
@@ -3421,7 +3432,7 @@ object Parsers {
3421
3432
3422
3433
/** GivenDef ::= [GivenSig] [‘_’ ‘<:’] Type ‘=’ Expr
3423
3434
* | [GivenSig] ConstrApps [TemplateBody]
3424
- * GivenSig ::= [id] [DefTypeParamClause] {GivenParamClause} ‘as’
3435
+ * GivenSig ::= [id] [DefTypeParamClause] GivenParamClauses ‘as’
3425
3436
* ExtParamClause ::= [DefTypeParamClause] DefParamClause
3426
3437
* ExtMethods ::= [nl] ‘{’ ‘def’ DefDef {semi ‘def’ DefDef} ‘}’
3427
3438
*/
@@ -3453,7 +3464,7 @@ object Parsers {
3453
3464
val tparams = typeParamClauseOpt(ParamOwner .Def )
3454
3465
val paramsStart = in.offset
3455
3466
val vparamss =
3456
- if in.token == LPAREN && followingIsParamOrGivenType()
3467
+ if in.token == WITH || in.token == LPAREN && followingIsParamOrGivenType()
3457
3468
then paramClauses()
3458
3469
else Nil
3459
3470
def checkAllGivens (vparamss : List [List [ValDef ]], what : String ) =
@@ -3496,7 +3507,7 @@ object Parsers {
3496
3507
finalizeDef(gdef, mods1, start)
3497
3508
}
3498
3509
3499
- /** ExtensionDef ::= [id] ‘on’ ExtParamClause {GivenParamClause} ExtMethods
3510
+ /** ExtensionDef ::= [id] ‘on’ ExtParamClause GivenParamClauses ExtMethods
3500
3511
*/
3501
3512
def extensionDef (start : Offset , mods : Modifiers ): ModuleDef =
3502
3513
in.nextToken()
0 commit comments