@@ -364,22 +364,22 @@ object Parsers {
364
364
365
365
/** Convert tree to formal parameter list
366
366
*/
367
- def convertToParams (tree : Tree , mods : Modifiers ): List [ValDef ] = tree match {
368
- case Parens (t) => convertToParam(t, mods ) :: Nil
369
- case Tuple (ts) => ts map (convertToParam(_, mods ))
370
- case t => convertToParam(t, mods ) :: Nil
367
+ def convertToParams (tree : Tree ): List [ValDef ] = tree match {
368
+ case Parens (t) => convertToParam(t) :: Nil
369
+ case Tuple (ts) => ts map (convertToParam(_))
370
+ case t => convertToParam(t) :: Nil
371
371
}
372
372
373
373
/** Convert tree to formal parameter
374
374
*/
375
- def convertToParam (tree : Tree , mods : Modifiers , expected : String = " formal parameter" ): ValDef = tree match {
375
+ def convertToParam (tree : Tree , expected : String = " formal parameter" ): ValDef = tree match {
376
376
case Ident (name) =>
377
- makeParameter(name.asTermName, TypeTree (), mods ).withSpan(tree.span)
377
+ makeParameter(name.asTermName, TypeTree ()).withSpan(tree.span)
378
378
case Typed (Ident (name), tpt) =>
379
- makeParameter(name.asTermName, tpt, mods ).withSpan(tree.span)
379
+ makeParameter(name.asTermName, tpt).withSpan(tree.span)
380
380
case _ =>
381
381
syntaxError(s " not a legal $expected" , tree.span)
382
- makeParameter(nme.ERROR , tree, mods )
382
+ makeParameter(nme.ERROR , tree)
383
383
}
384
384
385
385
/** Convert (qual)ident to type identifier
@@ -770,7 +770,7 @@ object Parsers {
770
770
*/
771
771
def toplevelTyp (): Tree = checkWildcard(typ())
772
772
773
- /** Type ::= [‘erased’] FunArgTypes (‘=>’ | ‘|=>’) Type
773
+ /** Type ::= FunTypeMods FunArgTypes `=>' Type
774
774
* | HkTypeParamClause `->' Type
775
775
* | InfixType
776
776
* FunArgTypes ::= InfixType
@@ -779,20 +779,11 @@ object Parsers {
779
779
*/
780
780
def typ (): Tree = {
781
781
val start = in.offset
782
- val imods = modifiers(BitSet ( ERASED ) )
782
+ val imods = modifiers(funTypeMods )
783
783
def functionRest (params : List [Tree ]): Tree =
784
- atSpan(start, in.offset) {
785
- val pmods =
786
- if (in.token == CARROW ) {
787
- in.nextToken()
788
- imods | (Contextual | Implicit )
789
- }
790
- else {
791
- accept(ARROW )
792
- imods
793
- }
784
+ atSpan(start, accept(ARROW )) {
794
785
val t = typ()
795
- if (pmods.flags. is(Implicit | Contextual | Erased )) new FunctionWithMods (params, t, pmods )
786
+ if (imods. is(Implicit | Contextual | Erased )) new FunctionWithMods (params, t, imods )
796
787
else Function (params, t)
797
788
}
798
789
def funArgTypesRest (first : Tree , following : () => Tree ) = {
@@ -826,7 +817,7 @@ object Parsers {
826
817
}
827
818
openParens.change(LPAREN , - 1 )
828
819
accept(RPAREN )
829
- if (imods.is(Implicit ) || isValParamList || in.token == ARROW || in.token == CARROW )
820
+ if (imods.is(Implicit ) || isValParamList || in.token == ARROW )
830
821
functionRest(ts)
831
822
else {
832
823
val ts1 =
@@ -858,7 +849,7 @@ object Parsers {
858
849
else infixType()
859
850
860
851
in.token match {
861
- case ARROW | CARROW => functionRest(t :: Nil )
852
+ case ARROW => functionRest(t :: Nil )
862
853
case MATCH => matchType(EmptyTree , t)
863
854
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported ()); t
864
855
case _ =>
@@ -1134,15 +1125,14 @@ object Parsers {
1134
1125
}
1135
1126
}
1136
1127
1137
- /** Expr ::= [FunArgMods] FunParams =>' Expr
1138
- * | [‘erased’] FunParams ‘|=>’ Expr
1128
+ /** Expr ::= [ClosureMods] FunParams =>' Expr
1139
1129
* | Expr1
1140
1130
* FunParams ::= Bindings
1141
1131
* | id
1142
1132
* | `_'
1143
1133
* ExprInParens ::= PostfixExpr `:' Type
1144
1134
* | Expr
1145
- * BlockResult ::= [FunArgMods ] FunParams =>' Block
1135
+ * BlockResult ::= [ClosureMods ] FunParams =>' Block
1146
1136
* | Expr1
1147
1137
* Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1148
1138
* | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -1171,8 +1161,8 @@ object Parsers {
1171
1161
1172
1162
def expr (location : Location .Value ): Tree = {
1173
1163
val start = in.offset
1174
- if (in.token == IMPLICIT || in.token == ERASED ) {
1175
- val imods = modifiers(funArgMods )
1164
+ if (in.token == IMPLICIT || in.token == ERASED || in.token == GIVEN ) {
1165
+ val imods = modifiers(closureMods )
1176
1166
if (in.token == MATCH ) implicitMatch(start, imods)
1177
1167
else implicitClosure(start, location, imods)
1178
1168
} else {
@@ -1185,11 +1175,9 @@ object Parsers {
1185
1175
finally placeholderParams = saved
1186
1176
1187
1177
val t = expr1(location)
1188
- if (in.token == ARROW || in.token == CARROW ) {
1178
+ if (in.token == ARROW ) {
1189
1179
placeholderParams = Nil // don't interpret `_' to the left of `=>` as placeholder
1190
- val impliedMods =
1191
- if (in.token == CARROW ) Modifiers (Implicit | Contextual ) else EmptyModifiers
1192
- wrapPlaceholders(closureRest(start, location, convertToParams(t, impliedMods)))
1180
+ wrapPlaceholders(closureRest(start, location, convertToParams(t)))
1193
1181
}
1194
1182
else if (isWildcard(t)) {
1195
1183
placeholderParams = placeholderParams ::: saved
@@ -1407,28 +1395,16 @@ object Parsers {
1407
1395
}
1408
1396
else ident()
1409
1397
1410
- /** Expr ::= FunArgMods FunParams `=>' Expr
1411
- * | [‘erased’] FunParams ‘|=>’ Expr
1398
+ /** Expr ::= ClosureMods FunParams `=>' Expr
1412
1399
* BlockResult ::= implicit id [`:' InfixType] `=>' Block // Scala2 only
1413
1400
*/
1414
1401
def implicitClosure (start : Int , location : Location .Value , implicitMods : Modifiers ): Tree =
1415
1402
closureRest(start, location, funParams(implicitMods, location))
1416
1403
1417
1404
def closureRest (start : Int , location : Location .Value , params : List [Tree ]): Tree =
1418
1405
atSpan(start, in.offset) {
1419
- val params1 =
1420
- if (in.token == CARROW ) {
1421
- in.nextToken()
1422
- params.map {
1423
- case param : ValDef => param.withMods(param.mods | (Implicit | Contextual ))
1424
- case param => param
1425
- }
1426
- }
1427
- else {
1428
- accept(ARROW )
1429
- params
1430
- }
1431
- Function (params1, if (location == Location .InBlock ) block() else expr())
1406
+ accept(ARROW )
1407
+ Function (params, if (location == Location .InBlock ) block() else expr())
1432
1408
}
1433
1409
1434
1410
/** PostfixExpr ::= InfixExpr [id [nl]]
@@ -1853,6 +1829,7 @@ object Parsers {
1853
1829
case ABSTRACT => Mod .Abstract ()
1854
1830
case FINAL => Mod .Final ()
1855
1831
case IMPLICIT => Mod .Implicit ()
1832
+ case GIVEN => Mod .Given ()
1856
1833
case ERASED => Mod .Erased ()
1857
1834
case LAZY => Mod .Lazy ()
1858
1835
case OVERRIDE => Mod .Override ()
@@ -1949,9 +1926,13 @@ object Parsers {
1949
1926
normalize(loop(start))
1950
1927
}
1951
1928
1952
- /** FunArgMods ::= { `implicit` | `erased` }
1929
+ /** FunArgMods ::= { `implicit` | `erased` }
1930
+ * ClosureMods ::= { ‘implicit’ | ‘erased’ | ‘given’}
1931
+ * FunTypeMods ::= { ‘erased’ | ‘given’}
1953
1932
*/
1954
- def funArgMods : BitSet = BitSet (IMPLICIT , ERASED )
1933
+ val funArgMods : BitSet = BitSet (IMPLICIT , ERASED )
1934
+ val closureMods : BitSet = BitSet (GIVEN , IMPLICIT , ERASED )
1935
+ val funTypeMods : BitSet = BitSet (GIVEN , ERASED )
1955
1936
1956
1937
/** Wrap annotation or constructor in New(...).<init> */
1957
1938
def wrapNew (tpt : Tree ): Select = Select (New (tpt), nme.CONSTRUCTOR )
@@ -2748,7 +2729,7 @@ object Parsers {
2748
2729
case Typed (tree @ This (EmptyTypeIdent ), tpt) =>
2749
2730
self = makeSelfDef(nme.WILDCARD , tpt).withSpan(first.span)
2750
2731
case _ =>
2751
- val ValDef (name, tpt, _) = convertToParam(first, EmptyModifiers , " self type clause" )
2732
+ val ValDef (name, tpt, _) = convertToParam(first, " self type clause" )
2752
2733
if (name != nme.ERROR )
2753
2734
self = makeSelfDef(name, tpt).withSpan(first.span)
2754
2735
}
@@ -2837,10 +2818,10 @@ object Parsers {
2837
2818
stats ++= importClause()
2838
2819
else if (isExprIntro)
2839
2820
stats += expr(Location .InBlock )
2840
- else if (isDefIntro(localModifierTokens))
2841
- if (in.token == IMPLICIT || in.token == ERASED ) {
2821
+ else if (isDefIntro(localModifierTokens) || in.token == GIVEN ) // !!!!
2822
+ if (in.token == IMPLICIT || in.token == ERASED || in.token == GIVEN ) {
2842
2823
val start = in.offset
2843
- var imods = modifiers(funArgMods )
2824
+ var imods = modifiers(closureMods )
2844
2825
if (isBindingIntro)
2845
2826
stats += implicitClosure(start, Location .InBlock , imods)
2846
2827
else if (in.token == MATCH )
0 commit comments