@@ -229,8 +229,14 @@ object Parsers {
229
229
if Feature .ccEnabled then
230
230
val lookahead = in.LookaheadScanner ()
231
231
lookahead.nextToken()
232
- val res = lookahead.isIdent(nme.cap) && lookahead.lookahead.token == TYPE
233
- res
232
+ lookahead.isIdent(nme.cap) && lookahead.lookahead.token == TYPE
233
+ else false
234
+ }
235
+ def isCapAssignmentNext = {
236
+ if isCapKw then
237
+ val lookahead = in.LookaheadScanner ()
238
+ lookahead.nextToken()
239
+ lookahead.isIdent && lookahead.lookahead.token == EQUALS
234
240
else false
235
241
}
236
242
def isSimpleLiteral =
@@ -1614,7 +1620,7 @@ object Parsers {
1614
1620
case _ => None
1615
1621
}
1616
1622
1617
- /** CaptureRef ::= { SimpleRef `.` } SimpleRef [`*`]
1623
+ /** CaptureRef ::= { SimpleRef `.` } SimpleRef [`*`] [`.` rd]
1618
1624
* | [ { SimpleRef `.` } SimpleRef `.` ] id
1619
1625
*/
1620
1626
def captureRef (): Tree =
@@ -1894,7 +1900,7 @@ object Parsers {
1894
1900
if in.token == LPAREN then funParamClause() :: funParamClauses() else Nil
1895
1901
1896
1902
/** InfixType ::= RefinedType {id [nl] RefinedType}
1897
- * | RefinedType `^` // under capture checking
1903
+ * | RefinedType `^` -- under captureChecking
1898
1904
*/
1899
1905
def infixType (inContextBound : Boolean = false ): Tree = infixTypeRest(inContextBound)(refinedType())
1900
1906
@@ -2182,44 +2188,47 @@ object Parsers {
2182
2188
atSpan(startOffset(t), startOffset(id)) { Select (t, id.name) }
2183
2189
}
2184
2190
2185
- /** ArgTypes ::= Type {`,' Type}
2186
- * | NamedTypeArg {`,' NamedTypeArg}
2187
- * NamedTypeArg ::= id `=' Type
2191
+ /** ArgTypes ::= TypeArg {‘,’ TypeArg}
2192
+ * | NamedTypeArg {‘,’ NamedTypeArg}
2193
+ * TypeArg ::= Type
2194
+ * | CaptureSet -- under captureChecking
2195
+ * NamedTypeArg ::= id ‘=’ Type
2196
+ * | ‘cap’ id ‘=’ CaptureSet -- under captureChecking
2188
2197
* NamesAndTypes ::= NameAndType {‘,’ NameAndType}
2189
- * NameAndType ::= id ':' Type
2198
+ * NameAndType ::= id ‘:’ Type
2190
2199
*/
2191
- def argTypes (namedOK : Boolean , wildOK : Boolean , tupleOK : Boolean ): List [Tree ] = // TODO grammar doc
2200
+ def argTypes (namedOK : Boolean , wildOK : Boolean , tupleOK : Boolean ): List [Tree ] =
2192
2201
inline def wildCardCheck (inline gen : Tree ): Tree =
2193
2202
val t = gen
2194
2203
if wildOK then t else rejectWildcardType(t)
2195
2204
2196
- def argType () = wildCardCheck :
2197
- typ()
2205
+ def argType () = wildCardCheck(typ())
2198
2206
2199
- def argOrCapType () = wildCardCheck :
2207
+ def typeArg () = wildCardCheck :
2200
2208
if Feature .ccEnabled && in.token == LBRACE && ! isDclIntroNext && ! isCapTypeKwNext then // is this a capture set and not a refinement type?
2201
2209
// This case is ambiguous w.r.t. an Object literal {}. But since CC is enabled, we probably expect it to designate the empty set
2202
2210
concreteCapsType(captureSet())
2203
2211
else typ()
2204
2212
2205
- def namedArgType () =
2213
+ def namedTypeArg () =
2206
2214
atSpan(in.offset):
2215
+ val isCap = if isCapKw then { in.nextToken(); true } else false
2207
2216
val name = ident()
2208
2217
accept(EQUALS )
2209
- NamedArg (name.toTypeName, argType())
2218
+ NamedArg (name.toTypeName, if isCap then concreteCapsType(captureSet()) else argType())
2210
2219
2211
- def namedElem () =
2220
+ def nameAndType () =
2212
2221
atSpan(in.offset):
2213
2222
val name = ident()
2214
2223
acceptColon()
2215
- NamedArg (name, argType()) // TODO allow capsets here?
2224
+ NamedArg (name, argType())
2216
2225
2217
- if namedOK && isIdent && in.lookahead.token == EQUALS then // TOOD support for named cap args
2218
- commaSeparated(() => namedArgType ())
2226
+ if namedOK && ( isIdent && in.lookahead.token == EQUALS || isCapAssignmentNext) then
2227
+ commaSeparated(() => namedTypeArg ())
2219
2228
else if tupleOK && isIdent && in.lookahead.isColon && sourceVersion.enablesNamedTuples then
2220
- commaSeparated(() => namedElem ())
2229
+ commaSeparated(() => nameAndType ())
2221
2230
else
2222
- commaSeparated(() => argOrCapType ())
2231
+ commaSeparated(() => typeArg ())
2223
2232
end argTypes
2224
2233
2225
2234
def paramTypeOf (core : () => Tree ): Tree =
@@ -3439,7 +3448,7 @@ object Parsers {
3439
3448
* | opaque
3440
3449
* LocalModifier ::= abstract | final | sealed | open | implicit | lazy | erased |
3441
3450
* inline | transparent | infix |
3442
- * mut | cap -- under cc
3451
+ * mut | cap -- under captureChecking
3443
3452
*/
3444
3453
def modifiers (allowed : BitSet = modifierTokens, start : Modifiers = Modifiers ()): Modifiers = {
3445
3454
@ tailrec
@@ -3529,20 +3538,24 @@ object Parsers {
3529
3538
end typeOrTermParamClauses
3530
3539
3531
3540
/** ClsTypeParamClause::= ‘[’ ClsTypeParam {‘,’ ClsTypeParam} ‘]’
3532
- * ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3533
- * id [HkTypeParamClause] TypeAndCtxBounds
3541
+ * ClsTypeParam ::= {Annotation} [‘+’ | ‘-’]
3542
+ * id [HkTypeParamClause] TypeAndCtxBounds
3543
+ * | {Annotation} ‘cap’ id CaptureSetAndCtxBounds -- under captureChecking
3534
3544
*
3535
3545
* DefTypeParamClause::= ‘[’ DefTypeParam {‘,’ DefTypeParam} ‘]’
3536
- * DefTypeParam ::= {Annotation}
3537
- * id [HkTypeParamClause] TypeAndCtxBounds
3546
+ * DefTypeParam ::= {Annotation}
3547
+ * id [HkTypeParamClause] TypeAndCtxBounds
3548
+ * | {Annotation} ‘cap’ id CaptureSetAndCtxBounds -- under captureChecking
3538
3549
*
3539
3550
* TypTypeParamClause::= ‘[’ TypTypeParam {‘,’ TypTypeParam} ‘]’
3540
- * TypTypeParam ::= {Annotation}
3541
- * (id | ‘_’) [HkTypeParamClause] TypeAndCtxBounds
3551
+ * TypTypeParam ::= {Annotation}
3552
+ * (id | ‘_’) [HkTypeParamClause] TypeAndCtxBounds
3553
+ * | {Annotation} ‘cap’ (id | ‘_’) CaptureSetAndCtxBounds -- under captureChecking
3542
3554
*
3543
3555
* HkTypeParamClause ::= ‘[’ HkTypeParam {‘,’ HkTypeParam} ‘]’
3544
- * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3545
- * (id | ‘_’) [HkTypePamClause] TypeBounds
3556
+ * HkTypeParam ::= {Annotation} [‘+’ | ‘-’]
3557
+ * (id | ‘_’) [HkTypePamClause] TypeBounds
3558
+ * | {Annotation} ‘cap’ (id | ‘_’) CaptureSetBounds -- under captureChecking
3546
3559
*/
3547
3560
def typeParamClause (paramOwner : ParamOwner ): List [TypeDef ] = inBracketsWithCommas {
3548
3561
@@ -3571,7 +3584,7 @@ object Parsers {
3571
3584
capParam(start, mods)
3572
3585
else typeParam(start, mods)
3573
3586
3574
- def capParam (startOffset : Int , mods0 : Modifiers ): TypeDef = { // TODO grammar doc
3587
+ def capParam (startOffset : Int , mods0 : Modifiers ): TypeDef = {
3575
3588
val start = startOffset
3576
3589
var mods = mods0
3577
3590
if paramOwner.isClass then
@@ -3964,7 +3977,7 @@ object Parsers {
3964
3977
* | var VarDef
3965
3978
* | def DefDef
3966
3979
* | type {nl} TypeDef
3967
- * | cap type {nl} CapDef -- under capture checking
3980
+ * | cap type {nl} CapDef -- under captureChecking
3968
3981
* | TmplDef
3969
3982
* EnumCase ::= `case' (id ClassConstr [`extends' ConstrApps]] | ids)
3970
3983
*/
@@ -4198,7 +4211,7 @@ object Parsers {
4198
4211
private def concreteCapsType (refs : List [Tree ]): Tree =
4199
4212
makeRetaining(Select (scalaDot(nme.caps), tpnme.CapSet ), refs, tpnme.retains)
4200
4213
4201
- /** CapDef ::= id CaptureSetAndCtxBounds [‘=’ CaptureSetOrRef] -- under capture checking
4214
+ /** CapDef ::= id CaptureSetAndCtxBounds [‘=’ CaptureSetOrRef] -- under captureChecking
4202
4215
*/
4203
4216
def capDefOrDcl (start : Offset , mods : Modifiers ): Tree =
4204
4217
newLinesOpt()
@@ -4825,7 +4838,7 @@ object Parsers {
4825
4838
* | ‘var’ VarDef
4826
4839
* | ‘def’ DefDef
4827
4840
* | ‘type’ {nl} TypeDef
4828
- * | ‘cap’ ‘type’ {nl} CapDef -- under capture checking
4841
+ * | ‘cap’ ‘type’ {nl} CapDef -- under captureChecking
4829
4842
* (in reality we admit class defs and vars and filter them out afterwards in `checkLegal`)
4830
4843
*/
4831
4844
def refineStatSeq (): List [Tree ] = {
0 commit comments