@@ -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
@@ -1569,15 +1573,15 @@ object Parsers {
15691573 else core()
15701574
15711575 /** Type ::= FunType
1572- * | HkTypeParamClause ‘=>>’ Type
1576+ * | TypTypeParamClause ‘=>>’ Type
15731577 * | FunParamClause ‘=>>’ Type
15741578 * | MatchType
15751579 * | InfixType
15761580 * FunType ::= (MonoFunType | PolyFunType)
15771581 * 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
15811585 * FunTypeArgs ::= InfixType
15821586 * | `(' [ FunArgType {`,' FunArgType } ] `)'
15831587 * | '(' [ TypedFunParam {',' TypedFunParam } ')'
@@ -1743,7 +1747,7 @@ object Parsers {
17431747 simpleTypeRest(tuple)
17441748 else if in.token == LBRACKET then
17451749 val start = in.offset
1746- val tparams = typeParamClause(ParamOwner .TypeParam )
1750+ val tparams = typeParamClause(ParamOwner .Type )
17471751 if in.token == TLARROW then
17481752 atSpan(start, in.skipToken()):
17491753 LambdaTypeTree (tparams, toplevelTyp())
@@ -2296,15 +2300,15 @@ object Parsers {
22962300 t
22972301
22982302 /** Expr ::= [`implicit'] FunParams (‘=>’ | ‘?=>’) Expr
2299- * | HkTypeParamClause ‘=>’ Expr
2303+ * | TypTypeParamClause ‘=>’ Expr
23002304 * | Expr1
23012305 * FunParams ::= Bindings
23022306 * | id
23032307 * | `_'
23042308 * ExprInParens ::= PostfixExpr `:' Type
23052309 * | Expr
23062310 * BlockResult ::= [‘implicit’] FunParams (‘=>’ | ‘?=>’) Block
2307- * | HkTypeParamClause ‘=>’ Block
2311+ * | TypTypeParamClause ‘=>’ Block
23082312 * | Expr1
23092313 * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
23102314 * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
@@ -2340,7 +2344,7 @@ object Parsers {
23402344 closure(start, location, modifiers(BitSet (IMPLICIT )))
23412345 case LBRACKET =>
23422346 val start = in.offset
2343- val tparams = typeParamClause(ParamOwner .TypeParam )
2347+ val tparams = typeParamClause(ParamOwner .Type )
23442348 val arrowOffset = accept(ARROW )
23452349 val body = expr(location)
23462350 atSpan(start, arrowOffset) {
@@ -2673,7 +2677,7 @@ object Parsers {
26732677 * ColonArgument ::= colon [LambdaStart]
26742678 * indent (CaseClauses | Block) outdent
26752679 * LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
2676- * | HkTypeParamClause ‘=>’
2680+ * | TypTypeParamClause ‘=>’
26772681 * ColonArgBody ::= indent (CaseClauses | Block) outdent
26782682 * Quoted ::= ‘'’ ‘{’ Block ‘}’
26792683 * | ‘'’ ‘[’ Type ‘]’
@@ -3390,17 +3394,19 @@ object Parsers {
33903394
33913395 /** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
33923396 * ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3393- * id [HkTypeParamClause] TypeParamBounds
3397+ * id [HkTypeParamClause] TypeAndCtxBounds
33943398 *
33953399 * DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
33963400 * DefTypeParam ::= {Annotation}
3397- * id [HkTypeParamClause] TypeParamBounds
3401+ * id [HkTypeParamClause] TypeAndCtxBounds
33983402 *
33993403 * TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3400- * TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
3404+ * TypTypeParam ::= {Annotation}
3405+ * (id | ‘_’) [HkTypeParamClause] TypeBounds
34013406 *
34023407 * HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3403- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypePamClause] | ‘_’) TypeBounds
3408+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3409+ * (id | ‘_’) [HkTypePamClause] TypeBounds
34043410 */
34053411 def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
34063412
@@ -3411,7 +3417,6 @@ object Parsers {
34113417 ok
34123418
34133419 def typeParam (): TypeDef = {
3414- val isAbstractOwner = paramOwner == ParamOwner .Type || paramOwner == ParamOwner .TypeParam
34153420 val start = in.offset
34163421 var mods = annotsAsMods() | Param
34173422 if paramOwner.isClass then
@@ -3422,13 +3427,13 @@ object Parsers {
34223427 mods |= Contravariant
34233428 atSpan(start, nameStart) {
34243429 val name =
3425- if (isAbstractOwner && in.token == USCORE ) {
3430+ if paramOwner.acceptsWildcard && in.token == USCORE then
34263431 in.nextToken()
34273432 WildcardParamName .fresh().toTypeName
3428- }
34293433 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()
34323437 TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
34333438 }
34343439 }
@@ -3938,14 +3943,14 @@ object Parsers {
39383943 argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
39393944 }
39403945
3941- /** TypeDef ::= id [TypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
3946+ /** TypeDef ::= id [HkTypeParamClause ] {FunParamClause} TypeAndCtxBounds [‘=’ Type]
39423947 */
39433948 def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
39443949 newLinesOpt()
39453950 atSpan(start, nameStart) {
39463951 val nameIdent = typeIdent()
39473952 val tname = nameIdent.name.asTypeName
3948- val tparams = typeParamClauseOpt(ParamOwner .Type )
3953+ val tparams = typeParamClauseOpt(ParamOwner .Hk )
39493954 val vparamss = funParamClauses()
39503955
39513956 def makeTypeDef (rhs : Tree ): Tree = {
0 commit comments