@@ -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
@@ -1565,15 +1569,15 @@ object Parsers {
1565
1569
else core()
1566
1570
1567
1571
/** Type ::= FunType
1568
- * | HkTypeParamClause ‘=>>’ Type
1572
+ * | TypTypeParamClause ‘=>>’ Type
1569
1573
* | FunParamClause ‘=>>’ Type
1570
1574
* | MatchType
1571
1575
* | InfixType
1572
1576
* FunType ::= (MonoFunType | PolyFunType)
1573
1577
* MonoFunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type
1574
- * | (‘->’ | ‘?->’ ) [CaptureSet] Type -- under pureFunctions
1575
- * PolyFunType ::= HKTypeParamClause '=>' Type
1576
- * | HKTypeParamClause ‘->’ [CaptureSet] Type -- under pureFunctions
1578
+ * | (‘->’ | ‘?->’ ) [CaptureSet] Type -- under pureFunctions
1579
+ * PolyFunType ::= TypTypeParamClause '=>' Type
1580
+ * | TypTypeParamClause ‘->’ [CaptureSet] Type -- under pureFunctions
1577
1581
* FunTypeArgs ::= InfixType
1578
1582
* | `(' [ FunArgType {`,' FunArgType } ] `)'
1579
1583
* | '(' [ TypedFunParam {',' TypedFunParam } ')'
@@ -1739,7 +1743,7 @@ object Parsers {
1739
1743
simpleTypeRest(tuple)
1740
1744
else if in.token == LBRACKET then
1741
1745
val start = in.offset
1742
- val tparams = typeParamClause(ParamOwner .TypeParam )
1746
+ val tparams = typeParamClause(ParamOwner .Type )
1743
1747
if in.token == TLARROW then
1744
1748
atSpan(start, in.skipToken()):
1745
1749
LambdaTypeTree (tparams, toplevelTyp())
@@ -2286,15 +2290,15 @@ object Parsers {
2286
2290
t
2287
2291
2288
2292
/** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr
2289
- * | HkTypeParamClause ‘=>’ Expr
2293
+ * | TypTypeParamClause ‘=>’ Expr
2290
2294
* | Expr1
2291
2295
* FunParams ::= Bindings
2292
2296
* | id
2293
2297
* | `_'
2294
2298
* ExprInParens ::= PostfixExpr `:' Type
2295
2299
* | Expr
2296
2300
* BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block
2297
- * | HkTypeParamClause ‘=>’ Block
2301
+ * | TypTypeParamClause ‘=>’ Block
2298
2302
* | Expr1
2299
2303
* Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
2300
2304
* | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -2330,7 +2334,7 @@ object Parsers {
2330
2334
closure(start, location, modifiers(BitSet (IMPLICIT )))
2331
2335
case LBRACKET =>
2332
2336
val start = in.offset
2333
- val tparams = typeParamClause(ParamOwner .TypeParam )
2337
+ val tparams = typeParamClause(ParamOwner .Type )
2334
2338
val arrowOffset = accept(ARROW )
2335
2339
val body = expr(location)
2336
2340
atSpan(start, arrowOffset) {
@@ -2663,7 +2667,7 @@ object Parsers {
2663
2667
* ColonArgument ::= colon [LambdaStart]
2664
2668
* indent (CaseClauses | Block) outdent
2665
2669
* LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
2666
- * | HkTypeParamClause ‘=>’
2670
+ * | TypTypeParamClause ‘=>’
2667
2671
* ColonArgBody ::= indent (CaseClauses | Block) outdent
2668
2672
* Quoted ::= ‘'’ ‘{’ Block ‘}’
2669
2673
* | ‘'’ ‘[’ Type ‘]’
@@ -3380,18 +3384,19 @@ object Parsers {
3380
3384
3381
3385
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
3382
3386
* ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3383
- * id [HkTypeParamClause] TypeParamBounds
3387
+ * id [HkTypeParamClause] TypeAndCtxBounds
3384
3388
*
3385
3389
* DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
3386
3390
* DefTypeParam ::= {Annotation}
3387
- * [`sealed`] -- under captureChecking
3388
- * id [HkTypeParamClause] TypeParamBounds
3391
+ * id [HkTypeParamClause] TypeAndCtxBounds
3389
3392
*
3390
3393
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3391
- * TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
3394
+ * TypTypeParam ::= {Annotation}
3395
+ * (id | ‘_’) [HkTypeParamClause] TypeBounds
3392
3396
*
3393
3397
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3394
- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
3398
+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3399
+ * (id | ‘_’) [HkTypePamClause] TypeBounds
3395
3400
*/
3396
3401
def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
3397
3402
@@ -3402,7 +3407,6 @@ object Parsers {
3402
3407
ok
3403
3408
3404
3409
def typeParam (): TypeDef = {
3405
- val isAbstractOwner = paramOwner == ParamOwner .Type || paramOwner == ParamOwner .TypeParam
3406
3410
val start = in.offset
3407
3411
var mods = annotsAsMods() | Param
3408
3412
if paramOwner.isClass then
@@ -3413,13 +3417,13 @@ object Parsers {
3413
3417
mods |= Contravariant
3414
3418
atSpan(start, nameStart) {
3415
3419
val name =
3416
- if (isAbstractOwner && in.token == USCORE ) {
3420
+ if paramOwner.acceptsWildcard && in.token == USCORE then
3417
3421
in.nextToken()
3418
3422
WildcardParamName .fresh().toTypeName
3419
- }
3420
3423
else ident().toTypeName
3421
- val hkparams = typeParamClauseOpt(ParamOwner .Type )
3422
- val bounds = if (isAbstractOwner) typeBounds() else typeAndCtxBounds(name)
3424
+ val hkparams = typeParamClauseOpt(ParamOwner .Hk )
3425
+ val bounds =
3426
+ if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name) else typeBounds()
3423
3427
TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3424
3428
}
3425
3429
}
@@ -3929,14 +3933,14 @@ object Parsers {
3929
3933
argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
3930
3934
}
3931
3935
3932
- /** TypeDef ::= id [TypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3936
+ /** TypeDef ::= id [HkTypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3933
3937
*/
3934
3938
def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
3935
3939
newLinesOpt()
3936
3940
atSpan(start, nameStart) {
3937
3941
val nameIdent = typeIdent()
3938
3942
val tname = nameIdent.name.asTypeName
3939
- val tparams = typeParamClauseOpt(ParamOwner .Type )
3943
+ val tparams = typeParamClauseOpt(ParamOwner .Hk )
3940
3944
val vparamss = funParamClauses()
3941
3945
3942
3946
def makeTypeDef (rhs : Tree ): Tree = {
0 commit comments