Skip to content

Commit 48e87da

Browse files
committed
Add lexical control delimiter test for captures
1 parent c2834c7 commit 48e87da

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,9 +1648,13 @@ object Parsers {
16481648

16491649
/** CaptureSet ::= ‘{’ CaptureRef {‘,’ CaptureRef} ‘}’ -- under captureChecking
16501650
*/
1651-
def captureSet(): List[Tree] = inBraces {
1652-
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1653-
}
1651+
def captureSet(): List[Tree] =
1652+
if in.token != LBRACE then
1653+
syntaxError(em"expected '{' to start capture set", in.offset)
1654+
Nil
1655+
else inBraces {
1656+
if in.token == RBRACE then Nil else commaSeparated(captureRef)
1657+
}
16541658

16551659
def capturesAndResult(core: () => Tree): Tree =
16561660
if Feature.ccEnabled && in.token == LBRACE && canStartCaptureSetContentsTokens.contains(in.lookahead.token)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import language.experimental.captureChecking
2+
import caps.*
3+
4+
trait Label extends Capability:
5+
cap type Fv // the capability set occurring freely in the `block` passed to `boundary` below.
6+
7+
def boundary[T, cap C](block: Label{cap type Fv = {C} } ->{C} T): T = ??? // link label and block capture set
8+
def suspend[U](label: Label)(handler: () ->{label.Fv} U): U = ??? // note the path
9+
10+
def test =
11+
val x = 1
12+
boundary: outer =>
13+
val y = 2
14+
boundary: inner =>
15+
val z = 3
16+
suspend(outer): () =>
17+
println(inner) // error (leaks the inner label)
18+
x + y + z

0 commit comments

Comments
 (0)