Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Oct 24, 2024
1 parent f6f996c commit 842240f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,10 @@ object CaptureSet:
// If this is the union of a constant and a variable,
// propagate `elem` to the variable part to avoid slack
// between the operands and the union.
// TODO: This means there's no back-propagation to the operands
// of a union of two variables. That could be a source of unsoundness.
// Altermative would be to be conservatibe and back-propagate to one
// of the operands arbitrarily or even to both of them.
if res.isOK && (origin ne cs1) && (origin ne cs2) then
if cs1.isConst then cs2.tryInclude(elem, origin)
else if cs2.isConst then cs1.tryInclude(elem, origin)
Expand Down
19 changes: 19 additions & 0 deletions tests/neg-custom-args/captures/delayedRunops1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import language.experimental.captureChecking

def runOps(ops: List[() => Unit]): () ->{ops*} Unit =
() => ops.foreach(op => op())

def app[T, U](x: T, op: T => U): () ->{op} U =
() => op(x)

def unsafeRunOps2(ops2: List[() => Unit]): () -> () -> Unit =
val x = app[List[() ->{ops2*} Unit], () ->{ops2*} Unit](ops2, runOps) // error
x

def unsafeRunOps3(ops2: List[() => Unit]): () -> () -> Unit =
val x = app(ops2, runOps) // error
x




21 changes: 21 additions & 0 deletions tests/neg-custom-args/captures/delayedRunops5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import language.experimental.captureChecking

def runOps(ops: List[() => Unit]): Unit =
ops.foreach(op => op())

def app[T, U](x: T, op: T => U): () ->{op} U =
() => op(x)

def test(c: Object^) =

def unsafeRunOps1(ops: List[() ->{c} Unit]): () -> Unit =
app[List[() ->{c} Unit], Unit](ops, runOps) // !!! ok, but should be error

def unsafeRunOps2(ops: List[() ->{c} Unit]): () -> Unit =
app(ops, runOps) // error

()




17 changes: 17 additions & 0 deletions tests/neg-custom-args/captures/delayedRunops6.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import language.experimental.captureChecking

val runOps: [C^] -> () -> (ops: List[() ->{C^} Unit]) ->{C^} Unit = ???

def app[T, U](x: T, op: T => U): () ->{op} U =
() => op(x)

def unsafeRunOps(ops: List[() => Unit]): () ->{} Unit =
app[List[() ->{ops*} Unit], Unit](ops, runOps()) // error

def unsafeRunOps2(ops: List[() => Unit]): () ->{} Unit =
app(ops, runOps()) // error

def test(c: Object^) =
def f = (ops: List[() ->{c} Unit]) => ops.foreach(_())
val _: List[() ->{c} Unit] ->{c} Unit = f
()

0 comments on commit 842240f

Please sign in to comment.