@@ -54,9 +54,9 @@ object Parsers {
54
54
enum ParamOwner :
55
55
case Class // class or trait or enum
56
56
case CaseClass // case class or enum case
57
- case Type // type alias or abstract type
58
- case TypeParam // type parameter
59
57
case Def // method
58
+ case Type // type alias or abstract type or polyfunction type/expr
59
+ case Hk // type parameter (i.e. current parameter is higher-kinded)
60
60
case Given // given definition
61
61
case ExtensionPrefix // extension clause, up to and including extension parameter
62
62
case ExtensionFollow // extension clause, following extension parameter
@@ -66,7 +66,11 @@ object Parsers {
66
66
def takesOnlyUsingClauses = // only using clauses allowed for this owner
67
67
this == Given || this == ExtensionFollow
68
68
def acceptsVariance =
69
- this == Class || this == CaseClass || this == Type
69
+ this == Class || this == CaseClass || this == Hk
70
+ def acceptsCtxBounds =
71
+ ! (this == Type || this == Hk )
72
+ def acceptsWildcard =
73
+ this == Type || this == Hk
70
74
71
75
end ParamOwner
72
76
@@ -1569,15 +1573,15 @@ object Parsers {
1569
1573
else core()
1570
1574
1571
1575
/** Type ::= FunType
1572
- * | HkTypeParamClause ‘=>>’ Type
1576
+ * | TypTypeParamClause ‘=>>’ Type
1573
1577
* | FunParamClause ‘=>>’ Type
1574
1578
* | MatchType
1575
1579
* | InfixType
1576
1580
* FunType ::= (MonoFunType | PolyFunType)
1577
1581
* MonoFunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type
1578
- * | (‘->’ | ‘?->’ ) [CaptureSet] Type -- under pureFunctions
1579
- * PolyFunType ::= HKTypeParamClause '=>' Type
1580
- * | HKTypeParamClause ‘->’ [CaptureSet] Type -- under pureFunctions
1582
+ * | (‘->’ | ‘?->’ ) [CaptureSet] Type -- under pureFunctions
1583
+ * PolyFunType ::= TypTypeParamClause '=>' Type
1584
+ * | TypTypeParamClause ‘->’ [CaptureSet] Type -- under pureFunctions
1581
1585
* FunTypeArgs ::= InfixType
1582
1586
* | `(' [ FunArgType {`,' FunArgType } ] `)'
1583
1587
* | '(' [ TypedFunParam {',' TypedFunParam } ')'
@@ -1743,7 +1747,7 @@ object Parsers {
1743
1747
simpleTypeRest(tuple)
1744
1748
else if in.token == LBRACKET then
1745
1749
val start = in.offset
1746
- val tparams = typeParamClause(ParamOwner .TypeParam )
1750
+ val tparams = typeParamClause(ParamOwner .Type )
1747
1751
if in.token == TLARROW then
1748
1752
atSpan(start, in.skipToken()):
1749
1753
LambdaTypeTree (tparams, toplevelTyp())
@@ -2296,15 +2300,15 @@ object Parsers {
2296
2300
t
2297
2301
2298
2302
/** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr
2299
- * | HkTypeParamClause ‘=>’ Expr
2303
+ * | TypTypeParamClause ‘=>’ Expr
2300
2304
* | Expr1
2301
2305
* FunParams ::= Bindings
2302
2306
* | id
2303
2307
* | `_'
2304
2308
* ExprInParens ::= PostfixExpr `:' Type
2305
2309
* | Expr
2306
2310
* BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block
2307
- * | HkTypeParamClause ‘=>’ Block
2311
+ * | TypTypeParamClause ‘=>’ Block
2308
2312
* | Expr1
2309
2313
* Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
2310
2314
* | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -2340,7 +2344,7 @@ object Parsers {
2340
2344
closure(start, location, modifiers(BitSet (IMPLICIT )))
2341
2345
case LBRACKET =>
2342
2346
val start = in.offset
2343
- val tparams = typeParamClause(ParamOwner .TypeParam )
2347
+ val tparams = typeParamClause(ParamOwner .Type )
2344
2348
val arrowOffset = accept(ARROW )
2345
2349
val body = expr(location)
2346
2350
atSpan(start, arrowOffset) {
@@ -2673,7 +2677,7 @@ object Parsers {
2673
2677
* ColonArgument ::= colon [LambdaStart]
2674
2678
* indent (CaseClauses | Block) outdent
2675
2679
* LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
2676
- * | HkTypeParamClause ‘=>’
2680
+ * | TypTypeParamClause ‘=>’
2677
2681
* ColonArgBody ::= indent (CaseClauses | Block) outdent
2678
2682
* Quoted ::= ‘'’ ‘{’ Block ‘}’
2679
2683
* | ‘'’ ‘[’ Type ‘]’
@@ -3390,17 +3394,19 @@ object Parsers {
3390
3394
3391
3395
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
3392
3396
* ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3393
- * id [HkTypeParamClause] TypeParamBounds
3397
+ * id [HkTypeParamClause] TypeAndCtxBounds
3394
3398
*
3395
3399
* DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
3396
3400
* DefTypeParam ::= {Annotation}
3397
- * id [HkTypeParamClause] TypeParamBounds
3401
+ * id [HkTypeParamClause] TypeAndCtxBounds
3398
3402
*
3399
3403
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3400
- * TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
3404
+ * TypTypeParam ::= {Annotation}
3405
+ * (id | ‘_’) [HkTypeParamClause] TypeBounds
3401
3406
*
3402
3407
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3403
- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
3408
+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3409
+ * (id | ‘_’) [HkTypePamClause] TypeBounds
3404
3410
*/
3405
3411
def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
3406
3412
@@ -3411,7 +3417,6 @@ object Parsers {
3411
3417
ok
3412
3418
3413
3419
def typeParam (): TypeDef = {
3414
- val isAbstractOwner = paramOwner == ParamOwner .Type || paramOwner == ParamOwner .TypeParam
3415
3420
val start = in.offset
3416
3421
var mods = annotsAsMods() | Param
3417
3422
if paramOwner.isClass then
@@ -3422,13 +3427,13 @@ object Parsers {
3422
3427
mods |= Contravariant
3423
3428
atSpan(start, nameStart) {
3424
3429
val name =
3425
- if (isAbstractOwner && in.token == USCORE ) {
3430
+ if paramOwner.acceptsWildcard && in.token == USCORE then
3426
3431
in.nextToken()
3427
3432
WildcardParamName .fresh().toTypeName
3428
- }
3429
3433
else ident().toTypeName
3430
- val hkparams = typeParamClauseOpt(ParamOwner .Type )
3431
- val bounds = if (isAbstractOwner) typeBounds() else typeAndCtxBounds(name)
3434
+ val hkparams = typeParamClauseOpt(ParamOwner .Hk )
3435
+ val bounds =
3436
+ if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) else typeBounds()
3432
3437
TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3433
3438
}
3434
3439
}
@@ -3938,14 +3943,14 @@ object Parsers {
3938
3943
argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
3939
3944
}
3940
3945
3941
- /** TypeDef ::= id [TypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3946
+ /** TypeDef ::= id [HkTypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3942
3947
*/
3943
3948
def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
3944
3949
newLinesOpt()
3945
3950
atSpan(start, nameStart) {
3946
3951
val nameIdent = typeIdent()
3947
3952
val tname = nameIdent.name.asTypeName
3948
- val tparams = typeParamClauseOpt(ParamOwner .Type )
3953
+ val tparams = typeParamClauseOpt(ParamOwner .Hk )
3949
3954
val vparamss = funParamClauses()
3950
3955
3951
3956
def makeTypeDef (rhs : Tree ): Tree = {
0 commit comments