@@ -1620,10 +1620,7 @@ object Parsers {
1620
1620
/** CaptureSet ::= `{` CaptureRef {`,` CaptureRef} `}` -- under captureChecking
1621
1621
*/
1622
1622
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 {
1627
1624
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1628
1625
}
1629
1626
@@ -3507,22 +3504,22 @@ object Parsers {
3507
3504
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
3508
3505
* ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3509
3506
* id [HkTypeParamClause] TypeAndCtxBounds
3510
- * | {Annotation} id [ `^`] TypeAndCtxBounds -- under captureChecking
3507
+ * | {Annotation} [‘+’ | ‘-’] id `^` TypeAndCtxBounds -- under captureChecking
3511
3508
*
3512
3509
* DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
3513
3510
* DefTypeParam ::= {Annotation}
3514
3511
* id [HkTypeParamClause] TypeAndCtxBounds
3515
- * | {Annotation} id [ `^`] TypeAndCtxBounds -- under captureChecking
3512
+ * | {Annotation} id `^` TypeAndCtxBounds -- under captureChecking
3516
3513
*
3517
3514
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3518
3515
* TypTypeParam ::= {Annotation}
3519
3516
* (id | ‘_’) [HkTypeParamClause] TypeAndCtxBounds
3520
- * | {Annotation} (id | ‘_’) [ `^`] TypeAndCtxBounds -- under captureChecking
3517
+ * | {Annotation} (id | ‘_’) `^` TypeAndCtxBounds -- under captureChecking
3521
3518
*
3522
3519
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3523
3520
* HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3524
3521
* (id | ‘_’) [HkTypePamClause] TypeBounds
3525
- * | {Annotation} (id | ‘_’) [ `^`] TypeBounds -- under captureChecking
3522
+ * | {Annotation} [‘+’ | ‘-’] (id | ‘_’) `^` TypeBounds -- under captureChecking
3526
3523
*/
3527
3524
def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
3528
3525
@@ -3548,26 +3545,16 @@ object Parsers {
3548
3545
WildcardParamName .fresh().toTypeName
3549
3546
else ident().toTypeName
3550
3547
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
3558
3548
val hkparams = typeParamClauseOpt(ParamOwner .Hk )
3559
3549
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)
3562
3552
else typeBounds()
3563
3553
val res = TypeDef (name, lambdaAbstract(hkparams, bounds)).withMods(mods)
3564
3554
if isCap then
3565
3555
res.pushAttachment(CaptureVar , ())
3566
3556
// putting the attachment here as well makes post-processing in the typer easier
3567
3557
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)
3571
3558
res
3572
3559
}
3573
3560
}
@@ -4090,7 +4077,7 @@ object Parsers {
4090
4077
}
4091
4078
4092
4079
/** TypeDef ::= id [HkTypeParamClause] {FunParamClause} TypeAndCtxBounds [‘=’ TypeDefRHS ]
4093
- * | id [ `^`] TypeAndCtxBounds [‘=’ TypeDefRHS ] -- under captureChecking
4080
+ * | id `^` TypeAndCtxBounds [‘=’ TypeDefRHS ] -- under captureChecking
4094
4081
* TypeDefRHS ::= Type
4095
4082
* | CaptureSet -- under captureChecking
4096
4083
*/
@@ -4105,21 +4092,19 @@ object Parsers {
4105
4092
atSpan(start, nameStart) {
4106
4093
val nameIdent = typeIdent()
4107
4094
val isCapDef = gobbleHat()
4108
- if isCapDef && in.token == LBRACKET then syntaxError(em " capture-set member declarations cannot have type parameters " )
4109
4095
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()
4112
4098
4113
4099
def makeTypeDef (rhs : Tree ): Tree = {
4114
4100
val rhs1 = lambdaAbstractAll(tparams :: vparamss, rhs)
4115
4101
val tdef = TypeDef (nameIdent.name.toTypeName, rhs1)
4116
4102
if nameIdent.isBackquoted then
4117
4103
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 , ())
4123
4108
finalizeDef(tdef, mods, start)
4124
4109
}
4125
4110
0 commit comments