@@ -35,7 +35,6 @@ import config.SourceVersion.*
35
35
import config .SourceVersion
36
36
import dotty .tools .dotc .config .MigrationVersion
37
37
import dotty .tools .dotc .util .chaining .*
38
- import dotty .tools .dotc .config .Feature .ccEnabled
39
38
40
39
object Parsers {
41
40
@@ -225,13 +224,23 @@ object Parsers {
225
224
def isCapKw = Feature .ccEnabled && isIdent(nme.cap)
226
225
// 'cap type' ?
227
226
def isCapTypeKw = isCapKw && in.lookahead.token == TYPE
227
+ // Are the next two tokens 'cap type'?
228
+ def isCapTypeKwNext = {
229
+ if Feature .ccEnabled then
230
+ val lookahead = in.LookaheadScanner ()
231
+ lookahead.nextToken()
232
+ val res = lookahead.isIdent(nme.cap) && lookahead.lookahead.token == TYPE
233
+ res
234
+ else false
235
+ }
228
236
def isSimpleLiteral =
229
237
simpleLiteralTokens.contains(in.token)
230
238
|| isIdent(nme.raw.MINUS ) && numericLitTokens.contains(in.lookahead.token)
231
239
def isLiteral = literalTokens contains in.token
232
240
def isNumericLit = numericLitTokens contains in.token
233
241
def isTemplateIntro = templateIntroTokens contains in.token
234
242
def isDclIntro = dclIntroTokens contains in.token
243
+ def isDclIntroNext = dclIntroTokens contains in.lookahead.token
235
244
def isStatSeqEnd = in.isNestedEnd || in.token == EOF || in.token == RPAREN
236
245
def mustStartStat = mustStartStatTokens contains in.token
237
246
@@ -1922,7 +1931,7 @@ object Parsers {
1922
1931
refinedTypeRest(atSpan(startOffset(t)) {
1923
1932
RefinedTypeTree (rejectWildcardType(t), refinement(indentOK = true ))
1924
1933
})
1925
- else if Feature .ccEnabled && in.isIdent(nme.UPARROW ) && isCaptureUpArrow then // TODO remove
1934
+ else if Feature .ccEnabled && in.isIdent(nme.UPARROW ) && isCaptureUpArrow then
1926
1935
atSpan(t.span.start):
1927
1936
in.nextToken()
1928
1937
if in.token == LBRACE
@@ -2179,13 +2188,19 @@ object Parsers {
2179
2188
* NamesAndTypes ::= NameAndType {‘,’ NameAndType}
2180
2189
* NameAndType ::= id ':' Type
2181
2190
*/
2182
- def argTypes (namedOK : Boolean , wildOK : Boolean , tupleOK : Boolean ): List [Tree ] = // TOOD grammar doc
2183
- def withWildCard ( gen : => Tree ) =
2191
+ def argTypes (namedOK : Boolean , wildOK : Boolean , tupleOK : Boolean ): List [Tree ] = // TODO grammar doc
2192
+ inline def wildCardCheck ( inline gen : Tree ): Tree =
2184
2193
val t = gen
2185
2194
if wildOK then t else rejectWildcardType(t)
2186
2195
2187
- def argType () = withWildCard(typ())
2188
- def argOrCapType () = withWildCard(if in.token == LBRACE then concreteCapsType(captureSet()) else typ())
2196
+ def argType () = wildCardCheck :
2197
+ typ()
2198
+
2199
+ def argOrCapType () = wildCardCheck :
2200
+ if Feature .ccEnabled && in.token == LBRACE && ! isDclIntroNext && ! isCapTypeKwNext then // is this a capture set and not a refinement type?
2201
+ // 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
+ concreteCapsType(captureSet())
2203
+ else typ()
2189
2204
2190
2205
def namedArgType () =
2191
2206
atSpan(in.offset):
0 commit comments