@@ -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
@@ -1572,15 +1576,15 @@ object Parsers {
1572
1576
else core()
1573
1577
1574
1578
/** Type ::= FunType
1575
- * | HkTypeParamClause ‘=>>’ Type
1579
+ * | TypTypeParamClause ‘=>>’ Type
1576
1580
* | FunParamClause ‘=>>’ Type
1577
1581
* | MatchType
1578
1582
* | InfixType
1579
1583
* FunType ::= (MonoFunType | PolyFunType)
1580
1584
* MonoFunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type
1581
- * | (‘->’ | ‘?->’ ) [CaptureSet] Type -- under pureFunctions
1582
- * PolyFunType ::= HKTypeParamClause '=>' Type
1583
- * | HKTypeParamClause ‘->’ [CaptureSet] Type -- under pureFunctions
1585
+ * | (‘->’ | ‘?->’ ) [CaptureSet] Type -- under pureFunctions
1586
+ * PolyFunType ::= TypTypeParamClause '=>' Type
1587
+ * | TypTypeParamClause ‘->’ [CaptureSet] Type -- under pureFunctions
1584
1588
* FunTypeArgs ::= InfixType
1585
1589
* | `(' [ FunArgType {`,' FunArgType } ] `)'
1586
1590
* | '(' [ TypedFunParam {',' TypedFunParam } ')'
@@ -1746,7 +1750,7 @@ object Parsers {
1746
1750
simpleTypeRest(tuple)
1747
1751
else if in.token == LBRACKET then
1748
1752
val start = in.offset
1749
- val tparams = typeParamClause(ParamOwner .TypeParam )
1753
+ val tparams = typeParamClause(ParamOwner .Type )
1750
1754
if in.token == TLARROW then
1751
1755
atSpan(start, in.skipToken()):
1752
1756
LambdaTypeTree (tparams, toplevelTyp())
@@ -2299,15 +2303,15 @@ object Parsers {
2299
2303
t
2300
2304
2301
2305
/** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr
2302
- * | HkTypeParamClause ‘=>’ Expr
2306
+ * | TypTypeParamClause ‘=>’ Expr
2303
2307
* | Expr1
2304
2308
* FunParams ::= Bindings
2305
2309
* | id
2306
2310
* | `_'
2307
2311
* ExprInParens ::= PostfixExpr `:' Type
2308
2312
* | Expr
2309
2313
* BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block
2310
- * | HkTypeParamClause ‘=>’ Block
2314
+ * | TypTypeParamClause ‘=>’ Block
2311
2315
* | Expr1
2312
2316
* Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
2313
2317
* | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -2343,7 +2347,7 @@ object Parsers {
2343
2347
closure(start, location, modifiers(BitSet (IMPLICIT )))
2344
2348
case LBRACKET =>
2345
2349
val start = in.offset
2346
- val tparams = typeParamClause(ParamOwner .TypeParam )
2350
+ val tparams = typeParamClause(ParamOwner .Type )
2347
2351
val arrowOffset = accept(ARROW )
2348
2352
val body = expr(location)
2349
2353
atSpan(start, arrowOffset) {
@@ -2676,7 +2680,7 @@ object Parsers {
2676
2680
* ColonArgument ::= colon [LambdaStart]
2677
2681
* indent (CaseClauses | Block) outdent
2678
2682
* LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
2679
- * | HkTypeParamClause ‘=>’
2683
+ * | TypTypeParamClause ‘=>’
2680
2684
* ColonArgBody ::= indent (CaseClauses | Block) outdent
2681
2685
* Quoted ::= ‘'’ ‘{’ Block ‘}’
2682
2686
* | ‘'’ ‘[’ Type ‘]’
@@ -3409,17 +3413,19 @@ object Parsers {
3409
3413
3410
3414
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
3411
3415
* ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3412
- * id [HkTypeParamClause] TypeParamBounds
3416
+ * id [HkTypeParamClause] TypeAndCtxBounds
3413
3417
*
3414
3418
* DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
3415
3419
* DefTypeParam ::= {Annotation}
3416
- * id [HkTypeParamClause] TypeParamBounds
3420
+ * id [HkTypeParamClause] TypeAndCtxBounds
3417
3421
*
3418
3422
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3419
- * TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
3423
+ * TypTypeParam ::= {Annotation}
3424
+ * (id | ‘_’) [HkTypeParamClause] TypeBounds
3420
3425
*
3421
3426
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3422
- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
3427
+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3428
+ * (id | ‘_’) [HkTypePamClause] TypeBounds
3423
3429
*/
3424
3430
def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
3425
3431
@@ -3430,7 +3436,6 @@ object Parsers {
3430
3436
ok
3431
3437
3432
3438
def typeParam (): TypeDef = {
3433
- val isAbstractOwner = paramOwner == ParamOwner .Type || paramOwner == ParamOwner .TypeParam
3434
3439
val start = in.offset
3435
3440
var mods = annotsAsMods() | Param
3436
3441
if paramOwner.isClass then
@@ -3441,13 +3446,13 @@ object Parsers {
3441
3446
mods |= Contravariant
3442
3447
atSpan(start, nameStart) {
3443
3448
val name =
3444
- if (isAbstractOwner && in.token == USCORE ) {
3449
+ if paramOwner.acceptsWildcard && in.token == USCORE then
3445
3450
in.nextToken()
3446
3451
WildcardParamName .fresh().toTypeName
3447
- }
3448
3452
else ident().toTypeName
3449
- val hkparams = typeParamClauseOpt(ParamOwner .Type )
3450
- val bounds = if (isAbstractOwner) typeBounds() else typeAndCtxBounds(name)
3453
+ val hkparams = typeParamClauseOpt(ParamOwner .Hk )
3454
+ val bounds =
3455
+ if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) else typeBounds()
3451
3456
TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3452
3457
}
3453
3458
}
@@ -3963,14 +3968,14 @@ object Parsers {
3963
3968
argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
3964
3969
}
3965
3970
3966
- /** TypeDef ::= id [TypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3971
+ /** TypeDef ::= id [HkTypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3967
3972
*/
3968
3973
def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
3969
3974
newLinesOpt()
3970
3975
atSpan(start, nameStart) {
3971
3976
val nameIdent = typeIdent()
3972
3977
val tname = nameIdent.name.asTypeName
3973
- val tparams = typeParamClauseOpt(ParamOwner .Type )
3978
+ val tparams = typeParamClauseOpt(ParamOwner .Hk )
3974
3979
val vparamss = funParamClauses()
3975
3980
3976
3981
def makeTypeDef (rhs : Tree ): Tree = {
0 commit comments