@@ -54,9 +54,9 @@ object Parsers {
5454 enum ParamOwner :
5555 case Class // class or trait or enum
5656 case CaseClass // case class or enum case
57- case Type // type alias or abstract type
58- case TypeParam // type parameter
5957 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)
6060 case Given // given definition
6161 case ExtensionPrefix // extension clause, up to and including extension parameter
6262 case ExtensionFollow // extension clause, following extension parameter
@@ -66,7 +66,11 @@ object Parsers {
6666 def takesOnlyUsingClauses = // only using clauses allowed for this owner
6767 this == Given || this == ExtensionFollow
6868 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
7074
7175 end ParamOwner
7276
@@ -1572,15 +1576,15 @@ object Parsers {
15721576 else core()
15731577
15741578 /** Type ::= FunType
1575- * | HkTypeParamClause ‘=>>’ Type
1579+ * | TypTypeParamClause ‘=>>’ Type
15761580 * | FunParamClause ‘=>>’ Type
15771581 * | MatchType
15781582 * | InfixType
15791583 * FunType ::= (MonoFunType | PolyFunType)
15801584 * 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
15841588 * FunTypeArgs ::= InfixType
15851589 * | `(' [ FunArgType {`,' FunArgType } ] `)'
15861590 * | '(' [ TypedFunParam {',' TypedFunParam } ')'
@@ -1746,7 +1750,7 @@ object Parsers {
17461750 simpleTypeRest(tuple)
17471751 else if in.token == LBRACKET then
17481752 val start = in.offset
1749- val tparams = typeParamClause(ParamOwner .TypeParam )
1753+ val tparams = typeParamClause(ParamOwner .Type )
17501754 if in.token == TLARROW then
17511755 atSpan(start, in.skipToken()):
17521756 LambdaTypeTree (tparams, toplevelTyp())
@@ -2299,15 +2303,15 @@ object Parsers {
22992303 t
23002304
23012305 /** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr
2302- * | HkTypeParamClause ‘=>’ Expr
2306+ * | TypTypeParamClause ‘=>’ Expr
23032307 * | Expr1
23042308 * FunParams ::= Bindings
23052309 * | id
23062310 * | `_'
23072311 * ExprInParens ::= PostfixExpr `:' Type
23082312 * | Expr
23092313 * BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block
2310- * | HkTypeParamClause ‘=>’ Block
2314+ * | TypTypeParamClause ‘=>’ Block
23112315 * | Expr1
23122316 * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
23132317 * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -2343,7 +2347,7 @@ object Parsers {
23432347 closure(start, location, modifiers(BitSet (IMPLICIT )))
23442348 case LBRACKET =>
23452349 val start = in.offset
2346- val tparams = typeParamClause(ParamOwner .TypeParam )
2350+ val tparams = typeParamClause(ParamOwner .Type )
23472351 val arrowOffset = accept(ARROW )
23482352 val body = expr(location)
23492353 atSpan(start, arrowOffset) {
@@ -2676,7 +2680,7 @@ object Parsers {
26762680 * ColonArgument ::= colon [LambdaStart]
26772681 * indent (CaseClauses | Block) outdent
26782682 * LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
2679- * | HkTypeParamClause ‘=>’
2683+ * | TypTypeParamClause ‘=>’
26802684 * ColonArgBody ::= indent (CaseClauses | Block) outdent
26812685 * Quoted ::= ‘'’ ‘{’ Block ‘}’
26822686 * | ‘'’ ‘[’ Type ‘]’
@@ -3409,17 +3413,19 @@ object Parsers {
34093413
34103414 /** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
34113415 * ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3412- * id [HkTypeParamClause] TypeParamBounds
3416+ * id [HkTypeParamClause] TypeAndCtxBounds
34133417 *
34143418 * DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
34153419 * DefTypeParam ::= {Annotation}
3416- * id [HkTypeParamClause] TypeParamBounds
3420+ * id [HkTypeParamClause] TypeAndCtxBounds
34173421 *
34183422 * TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3419- * TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
3423+ * TypTypeParam ::= {Annotation}
3424+ * (id | ‘_’) [HkTypeParamClause] TypeBounds
34203425 *
34213426 * HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3422- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
3427+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3428+ * (id | ‘_’) [HkTypePamClause] TypeBounds
34233429 */
34243430 def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
34253431
@@ -3430,7 +3436,6 @@ object Parsers {
34303436 ok
34313437
34323438 def typeParam (): TypeDef = {
3433- val isAbstractOwner = paramOwner == ParamOwner .Type || paramOwner == ParamOwner .TypeParam
34343439 val start = in.offset
34353440 var mods = annotsAsMods() | Param
34363441 if paramOwner.isClass then
@@ -3441,13 +3446,13 @@ object Parsers {
34413446 mods |= Contravariant
34423447 atSpan(start, nameStart) {
34433448 val name =
3444- if (isAbstractOwner && in.token == USCORE ) {
3449+ if paramOwner.acceptsWildcard && in.token == USCORE then
34453450 in.nextToken()
34463451 WildcardParamName .fresh().toTypeName
3447- }
34483452 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()
34513456 TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
34523457 }
34533458 }
@@ -3963,14 +3968,14 @@ object Parsers {
39633968 argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
39643969 }
39653970
3966- /** TypeDef ::= id [TypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3971+ /** TypeDef ::= id [HkTypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
39673972 */
39683973 def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
39693974 newLinesOpt()
39703975 atSpan(start, nameStart) {
39713976 val nameIdent = typeIdent()
39723977 val tname = nameIdent.name.asTypeName
3973- val tparams = typeParamClauseOpt(ParamOwner .Type )
3978+ val tparams = typeParamClauseOpt(ParamOwner .Hk )
39743979 val vparamss = funParamClauses()
39753980
39763981 def makeTypeDef (rhs : Tree ): Tree = {
0 commit comments