@@ -3194,7 +3194,9 @@ object Parsers {
3194
3194
* id [HkTypeParamClause] TypeParamBounds
3195
3195
*
3196
3196
* DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
3197
- * DefTypeParam ::= {Annotation} id [HkTypeParamClause] TypeParamBounds
3197
+ * DefTypeParam ::= {Annotation}
3198
+ * [`sealed`] -- under captureChecking
3199
+ * id [HkTypeParamClause] TypeParamBounds
3198
3200
*
3199
3201
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3200
3202
* TypTypeParam ::= {Annotation} id [HkTypePamClause] TypeBounds
@@ -3204,24 +3206,24 @@ object Parsers {
3204
3206
*/
3205
3207
def typeParamClause (ownerKind : ParamOwner ): List [TypeDef ] = inBrackets {
3206
3208
3207
- def variance (vflag : FlagSet ): FlagSet =
3208
- if ownerKind == ParamOwner .Def || ownerKind == ParamOwner .TypeParam then
3209
- syntaxError(em " no `+/-` variance annotation allowed here " )
3210
- in.nextToken()
3211
- EmptyFlags
3212
- else
3213
- in.nextToken()
3214
- vflag
3209
+ def checkVarianceOK (): Boolean =
3210
+ val ok = ownerKind != ParamOwner .Def && ownerKind != ParamOwner .TypeParam
3211
+ if ! ok then syntaxError(em " no `+/-` variance annotation allowed here " )
3212
+ in.nextToken()
3213
+ ok
3215
3214
3216
3215
def typeParam (): TypeDef = {
3217
3216
val isAbstractOwner = ownerKind == ParamOwner .Type || ownerKind == ParamOwner .TypeParam
3218
3217
val start = in.offset
3219
- val mods =
3220
- annotsAsMods()
3221
- | (if (ownerKind == ParamOwner .Class ) Param | PrivateLocal else Param )
3222
- | (if isIdent(nme.raw.PLUS ) then variance(Covariant )
3223
- else if isIdent(nme.raw.MINUS ) then variance(Contravariant )
3224
- else EmptyFlags )
3218
+ var mods = annotsAsMods() | Param
3219
+ if ownerKind == ParamOwner .Class then mods |= PrivateLocal
3220
+ if Feature .ccEnabled && in.token == SEALED then
3221
+ mods |= Sealed
3222
+ in.nextToken()
3223
+ if isIdent(nme.raw.PLUS ) && checkVarianceOK() then
3224
+ mods |= Covariant
3225
+ else if isIdent(nme.raw.MINUS ) && checkVarianceOK() then
3226
+ mods |= Contravariant
3225
3227
atSpan(start, nameStart) {
3226
3228
val name =
3227
3229
if (isAbstractOwner && in.token == USCORE ) {
0 commit comments