Skip to content

Commit 842240f

Browse files
committed
More tests
1 parent f6f996c commit 842240f

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ object CaptureSet:
821821
// If this is the union of a constant and a variable,
822822
// propagate `elem` to the variable part to avoid slack
823823
// between the operands and the union.
824+
// TODO: This means there's no back-propagation to the operands
825+
// of a union of two variables. That could be a source of unsoundness.
826+
// Altermative would be to be conservatibe and back-propagate to one
827+
// of the operands arbitrarily or even to both of them.
824828
if res.isOK && (origin ne cs1) && (origin ne cs2) then
825829
if cs1.isConst then cs2.tryInclude(elem, origin)
826830
else if cs2.isConst then cs1.tryInclude(elem, origin)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import language.experimental.captureChecking
2+
3+
def runOps(ops: List[() => Unit]): () ->{ops*} Unit =
4+
() => ops.foreach(op => op())
5+
6+
def app[T, U](x: T, op: T => U): () ->{op} U =
7+
() => op(x)
8+
9+
def unsafeRunOps2(ops2: List[() => Unit]): () -> () -> Unit =
10+
val x = app[List[() ->{ops2*} Unit], () ->{ops2*} Unit](ops2, runOps) // error
11+
x
12+
13+
def unsafeRunOps3(ops2: List[() => Unit]): () -> () -> Unit =
14+
val x = app(ops2, runOps) // error
15+
x
16+
17+
18+
19+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import language.experimental.captureChecking
2+
3+
def runOps(ops: List[() => Unit]): Unit =
4+
ops.foreach(op => op())
5+
6+
def app[T, U](x: T, op: T => U): () ->{op} U =
7+
() => op(x)
8+
9+
def test(c: Object^) =
10+
11+
def unsafeRunOps1(ops: List[() ->{c} Unit]): () -> Unit =
12+
app[List[() ->{c} Unit], Unit](ops, runOps) // !!! ok, but should be error
13+
14+
def unsafeRunOps2(ops: List[() ->{c} Unit]): () -> Unit =
15+
app(ops, runOps) // error
16+
17+
()
18+
19+
20+
21+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import language.experimental.captureChecking
2+
3+
val runOps: [C^] -> () -> (ops: List[() ->{C^} Unit]) ->{C^} Unit = ???
4+
5+
def app[T, U](x: T, op: T => U): () ->{op} U =
6+
() => op(x)
7+
8+
def unsafeRunOps(ops: List[() => Unit]): () ->{} Unit =
9+
app[List[() ->{ops*} Unit], Unit](ops, runOps()) // error
10+
11+
def unsafeRunOps2(ops: List[() => Unit]): () ->{} Unit =
12+
app(ops, runOps()) // error
13+
14+
def test(c: Object^) =
15+
def f = (ops: List[() ->{c} Unit]) => ops.foreach(_())
16+
val _: List[() ->{c} Unit] ->{c} Unit = f
17+
()

0 commit comments

Comments
 (0)