@@ -3179,9 +3179,7 @@ object Parsers {
3179
3179
* id [HkTypeParamClause] TypeParamBounds
3180
3180
*
3181
3181
* DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
3182
- * DefTypeParam ::= {Annotation}
3183
- * [`sealed`] -- under captureChecking
3184
- * id [HkTypeParamClause] TypeParamBounds
3182
+ * DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
3185
3183
*
3186
3184
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3187
3185
* TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
@@ -3191,25 +3189,24 @@ object Parsers {
3191
3189
*/
3192
3190
def typeParamClause (ownerKind : ParamOwner ): List [TypeDef ] = inBrackets {
3193
3191
3194
- def checkVarianceOK (): Boolean =
3195
- val ok = ownerKind != ParamOwner .Def && ownerKind != ParamOwner .TypeParam
3196
- if ! ok then syntaxError(em " no `+/-` variance annotation allowed here " )
3197
- in.nextToken()
3198
- ok
3192
+ def variance (vflag : FlagSet ): FlagSet =
3193
+ if ownerKind == ParamOwner .Def || ownerKind == ParamOwner .TypeParam then
3194
+ syntaxError(em " no `+/-` variance annotation allowed here " )
3195
+ in.nextToken()
3196
+ EmptyFlags
3197
+ else
3198
+ in.nextToken()
3199
+ vflag
3199
3200
3200
3201
def typeParam (): TypeDef = {
3201
3202
val isAbstractOwner = ownerKind == ParamOwner .Type || ownerKind == ParamOwner .TypeParam
3202
3203
val start = in.offset
3203
- var mods = annotsAsMods() | Param
3204
- if ownerKind == ParamOwner .Class then mods |= PrivateLocal
3205
- if Feature .ccEnabled && in.token == SEALED then
3206
- if ownerKind == ParamOwner .Def then mods |= Sealed
3207
- else syntaxError(em " `sealed` modifier only allowed for method type parameters " )
3208
- in.nextToken()
3209
- if isIdent(nme.raw.PLUS ) && checkVarianceOK() then
3210
- mods |= Covariant
3211
- else if isIdent(nme.raw.MINUS ) && checkVarianceOK() then
3212
- mods |= Contravariant
3204
+ val mods =
3205
+ annotsAsMods()
3206
+ | (if (ownerKind == ParamOwner .Class ) Param | PrivateLocal else Param )
3207
+ | (if isIdent(nme.raw.PLUS ) then variance(Covariant )
3208
+ else if isIdent(nme.raw.MINUS ) then variance(Contravariant )
3209
+ else EmptyFlags )
3213
3210
atSpan(start, nameStart) {
3214
3211
val name =
3215
3212
if (isAbstractOwner && in.token == USCORE ) {
0 commit comments