From d1fab190f6db4c1184af6b02e3db585d7f76e70a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 17 Jun 2021 17:01:00 +0200 Subject: [PATCH] Add IO test --- tests/neg-custom-args/captures/io.scala | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/neg-custom-args/captures/io.scala diff --git a/tests/neg-custom-args/captures/io.scala b/tests/neg-custom-args/captures/io.scala new file mode 100644 index 000000000000..a9636b045694 --- /dev/null +++ b/tests/neg-custom-args/captures/io.scala @@ -0,0 +1,21 @@ +sealed trait IO: + def puts(msg: Any): Unit = println(msg) + +def test1 = + val IO : IO retains * = new IO {} + def foo = IO.puts("hello") + val x : () => Unit = () => foo // error: Found: (() => Unit) retains IO; Required: () => Unit + +def test2 = + val IO : IO retains * = new IO {} + def puts(msg: Any, io: IO retains *) = println(msg) + def foo() = puts("hello", IO) + val x : () => Unit = () => foo() // error: Found: (() => Unit) retains IO; Required: () => Unit + +type Capability[T] = T retains * + +def test3 = + val IO : Capability[IO] = new IO {} + def puts(msg: Any, io: Capability[IO]) = println(msg) + def foo() = puts("hello", IO) + val x : () => Unit = () => foo() // error: Found: (() => Unit) retains IO; Required: () => Unit