Skip to content

Commit 0570d43

Browse files
committed
Support cap params in type refinements
1 parent c41113d commit 0570d43

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ object Parsers {
225225
def isErasedKw = isErased && in.isSoftModifierInParamModifierPosition
226226
// Are we seeing a `cap` soft keyword for declaring a capture-set member or at the beginning a capture-variable parameter list?
227227
def isCapKw = Feature.ccEnabled && isIdent(nme.cap)
228+
// This will typically be used at the beginning of a type parameter list to check if it is a capture-variable parameter list:
228229
def isCapKwNext = Feature.ccEnabled && in.lookahead.isIdent(nme.cap)
229230
def isSimpleLiteral =
230231
simpleLiteralTokens.contains(in.token)
@@ -1916,7 +1917,7 @@ object Parsers {
19161917
refinedTypeRest(atSpan(startOffset(t)) {
19171918
RefinedTypeTree(rejectWildcardType(t), refinement(indentOK = true))
19181919
})
1919-
else if Feature.ccEnabled && in.isIdent(nme.UPARROW) && isCaptureUpArrow then
1920+
else if Feature.ccEnabled && in.isIdent(nme.UPARROW) && isCaptureUpArrow then // TODO remove
19201921
atSpan(t.span.start):
19211922
in.nextToken()
19221923
if in.token == LBRACE
@@ -4858,7 +4859,7 @@ object Parsers {
48584859
fail(em"this kind of definition cannot be a refinement")
48594860

48604861
while
4861-
val dclFound = isDclIntro
4862+
val dclFound = isDclIntro || isCapKw // TODO grammar doc
48624863
if dclFound then
48634864
stats ++= checkLegal(defOrDcl(in.offset, Modifiers()))
48644865
var what = "declaration"

tests/pos-custom-args/captures/cap-paramlists.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ def test2 =
3838
def foo[cap A, B >: A](x: Int) = 1
3939
foo[cap x, x](0)
4040
foo[cap A = x, B = {x}](0)
41-
foo[cap A = {x}](0)
41+
foo[cap A = {x}](0)
42+
43+
trait Bar:
44+
cap C
45+
46+
def useFoo[cap D](x: Bar { cap C = D} ): Any^{x.C} = ???

0 commit comments

Comments
 (0)