@@ -1620,10 +1620,7 @@ object Parsers {
16201620 /** CaptureSet ::= `{` CaptureRef {`,` CaptureRef} `}` -- under captureChecking
16211621 */
16221622 def captureSet (): List [Tree ] =
1623- if in.token != LBRACE then
1624- syntaxError(em " expected '{' to start capture set " , in.offset)
1625- Nil
1626- else inBraces {
1623+ inBraces {
16271624 if in.token == RBRACE then Nil else commaSeparated(captureRef)
16281625 }
16291626
@@ -3507,22 +3504,22 @@ object Parsers {
35073504 /** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
35083505 * ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
35093506 * id [HkTypeParamClause] TypeAndCtxBounds
3510- * | {Annotation} id [ `^`] TypeAndCtxBounds -- under captureChecking
3507+ * | {Annotation} [‘+’ | ‘-’] id `^` TypeAndCtxBounds -- under captureChecking
35113508 *
35123509 * DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
35133510 * DefTypeParam ::= {Annotation}
35143511 * id [HkTypeParamClause] TypeAndCtxBounds
3515- * | {Annotation} id [ `^`] TypeAndCtxBounds -- under captureChecking
3512+ * | {Annotation} id `^` TypeAndCtxBounds -- under captureChecking
35163513 *
35173514 * TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
35183515 * TypTypeParam ::= {Annotation}
35193516 * (id | ‘_’) [HkTypeParamClause] TypeAndCtxBounds
3520- * | {Annotation} (id | ‘_’) [ `^`] TypeAndCtxBounds -- under captureChecking
3517+ * | {Annotation} (id | ‘_’) `^` TypeAndCtxBounds -- under captureChecking
35213518 *
35223519 * HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
35233520 * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
35243521 * (id | ‘_’) [HkTypePamClause] TypeBounds
3525- * | {Annotation} (id | ‘_’) [ `^`] TypeBounds -- under captureChecking
3522+ * | {Annotation} [‘+’ | ‘-’] (id | ‘_’) `^` TypeBounds -- under captureChecking
35263523 */
35273524 def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
35283525
@@ -3548,26 +3545,16 @@ object Parsers {
35483545 WildcardParamName .fresh().toTypeName
35493546 else ident().toTypeName
35503547 val isCap = gobbleHat()
3551- if isCap then
3552- if mods.isOneOf(Covariant | Contravariant ) then
3553- syntaxError(em " capture parameters cannot have `+/-` variance annotations " ) // TODO we might want to allow those
3554- if in.token == LBRACKET then
3555- syntaxError(em " capture parameters do not take type parameters " )
3556- in.nextToken()
3557- end if
35583548 val hkparams = typeParamClauseOpt(ParamOwner .Hk )
35593549 val bounds =
3560- if ! isCap && paramOwner.acceptsCtxBounds then typeAndCtxBounds(name)
3561- else if ! isCap && sourceVersion.enablesNewGivens && paramOwner == ParamOwner .Type then typeAndCtxBounds(name)
3550+ if paramOwner.acceptsCtxBounds then typeAndCtxBounds(name)
3551+ else if sourceVersion.enablesNewGivens && paramOwner == ParamOwner .Type then typeAndCtxBounds(name)
35623552 else typeBounds()
35633553 val res = TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
35643554 if isCap then
35653555 res.pushAttachment(CaptureVar , ())
35663556 // putting the attachment here as well makes post-processing in the typer easier
35673557 bounds.pushAttachment(CaptureVar , ())
3568- val t = contextBounds(name)
3569- if t.nonEmpty then
3570- syntaxError(em " capture parameters cannot have context bounds " , t.head.span)
35713558 res
35723559 }
35733560 }
@@ -4090,7 +4077,7 @@ object Parsers {
40904077 }
40914078
40924079 /** TypeDef ::= id [HkTypeParamClause] {FunParamClause} TypeAndCtxBounds [‘=’ TypeDefRHS ]
4093- * | id [ `^`] TypeAndCtxBounds [‘=’ TypeDefRHS ] -- under captureChecking
4080+ * | id `^` TypeAndCtxBounds [‘=’ TypeDefRHS ] -- under captureChecking
40944081 * TypeDefRHS ::= Type
40954082 * | CaptureSet -- under captureChecking
40964083 */
@@ -4105,21 +4092,19 @@ object Parsers {
41054092 atSpan(start, nameStart) {
41064093 val nameIdent = typeIdent()
41074094 val isCapDef = gobbleHat()
4108- if isCapDef && in.token == LBRACKET then syntaxError(em " capture-set member declarations cannot have type parameters " )
41094095 val tname = nameIdent.name.asTypeName
4110- val tparams = if ! isCapDef then typeParamClauseOpt(ParamOwner .Hk ) else Nil
4111- val vparamss = if ! isCapDef then funParamClauses() else Nil
4096+ val tparams = typeParamClauseOpt(ParamOwner .Hk )
4097+ val vparamss = funParamClauses()
41124098
41134099 def makeTypeDef (rhs : Tree ): Tree = {
41144100 val rhs1 = lambdaAbstractAll(tparams :: vparamss, rhs)
41154101 val tdef = TypeDef (nameIdent.name.toTypeName, rhs1)
41164102 if nameIdent.isBackquoted then
41174103 tdef.pushAttachment(Backquoted , ())
4118- if isCapDef then rhs.match
4119- case ContextBounds (_, _) => syntaxError(em " capture-set member declarations cannot have context bounds " , rhs.span)
4120- case rhs => tdef.pushAttachment(CaptureVar , ())
4121- // putting the attachment here as well makes post-processing in the typer easier
4122- rhs.pushAttachment(CaptureVar , ())
4104+ if isCapDef then
4105+ tdef.pushAttachment(CaptureVar , ())
4106+ // putting the attachment here as well makes post-processing in the typer easier
4107+ rhs.pushAttachment(CaptureVar , ())
41234108 finalizeDef(tdef, mods, start)
41244109 }
41254110
0 commit comments