Skip to content

Commit 50419ac

Browse files
committed
Adapt tests to local roots
1 parent 1a0be56 commit 50419ac

16 files changed

+112
-56
lines changed

tests/neg-custom-args/captures/boundschecks2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ object test {
88

99
val foo: C[Tree^] = ??? // error
1010
type T = C[Tree^] // error
11-
val bar: T -> T = ???
11+
val bar: T -> T = ??? // error
1212
val baz: C[Tree^] -> Unit = ??? // error
1313
}

tests/neg-custom-args/captures/ctest.scala

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/neg-custom-args/captures/filevar.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ class File:
55
def write(x: String): Unit = ???
66

77
class Service:
8-
var file: File^ = uninitialized // error
8+
var file: File^ = uninitialized
99
def log = file.write("log")
1010

11-
def withFile[T](op: (f: File^) => T): T =
11+
def withFile[T](op: (l: caps.Root) ?-> (f: File^{l}) => T): T =
1212
op(new File)
1313

1414
def test =
1515
withFile: f =>
1616
val o = Service()
17-
o.file = f
17+
o.file = f // error
1818
o.log

tests/neg-custom-args/captures/i15049.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Session:
22
def request = "Response"
33
class Foo:
44
private val session: Session^{cap} = new Session
5-
def withSession[sealed T](f: (Session^{cap}) => T): T = f(session)
5+
def withSession[T](f: (local: caps.Root) ?-> (Session^{local}) => T): T = f(session)
66

77
def Test: Unit =
88
val f = new Foo

tests/neg-custom-args/captures/i15772.check

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:20:46 ---------------------------------------
77
20 | val boxed1 : ((C^) => Unit) -> Unit = box1(c) // error
88
| ^^^^^^^
9-
| Found: (C{val arg: C^}^{c} => Unit) ->{c} Unit
10-
| Required: (C^ => Unit) -> Unit
9+
| Found: (C{val arg: C^{cap[C]}}^{c} ->{'cap[..main1](from instantiating box1), c} Unit) ->{c} Unit
10+
| Required: (C^ => Unit) -> Unit
1111
|
1212
| longer explanation available when compiling with `-explain`
1313
-- Error: tests/neg-custom-args/captures/i15772.scala:26:26 ------------------------------------------------------------
@@ -18,15 +18,28 @@
1818
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:27:35 ---------------------------------------
1919
27 | val boxed2 : Observe[C^] = box2(c) // error
2020
| ^^^^^^^
21-
| Found: (C{val arg: C^}^{c} => Unit) ->{c} Unit
22-
| Required: Observe[C^]
21+
| Found: (C{val arg: C^{cap[C]}}^{c} ->{'cap[..main2](from instantiating box2), c} Unit) ->{c} Unit
22+
| Required: (C^ => Unit) -> Unit
2323
|
2424
| longer explanation available when compiling with `-explain`
25-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:33:33 ---------------------------------------
25+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:33:34 ---------------------------------------
2626
33 | val boxed2 : Observe[C]^ = box2(c) // error
27-
| ^^^^^^^
28-
| Found: (C{val arg: C^}^ => Unit) ->? Unit
29-
| Required: Observe[C]^
27+
| ^
28+
| Found: box C^{cap[c]}
29+
| Required: box C{val arg: C^?}^?
30+
|
31+
| Note that reference (cap[c] : caps.Root), defined at level 2
32+
| cannot be included in outer capture set ?, defined at level 1 in method main3
33+
|
34+
| longer explanation available when compiling with `-explain`
35+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:34:29 ---------------------------------------
36+
34 | boxed2((cap: C^) => unsafe(c)) // error
37+
| ^
38+
| Found: C^{cap[c]}
39+
| Required: C^{'cap[..main3](from instantiating unsafe)}
40+
|
41+
| Note that reference (cap[c] : caps.Root), defined at level 2
42+
| cannot be included in outer capture set ?, defined at level 1 in method main3
3043
|
3144
| longer explanation available when compiling with `-explain`
3245
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:44:2 ----------------------------------------
@@ -35,4 +48,7 @@
3548
| Found: () ->{x} Unit
3649
| Required: () -> Unit
3750
|
51+
| Note that reference (cap[c] : caps.Root), defined at level 2
52+
| cannot be included in outer capture set ?, defined at level 1 in method main3
53+
|
3854
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/i15772.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def main2(x: C^) : () -> Int =
3131
def main3(x: C^) =
3232
def c : C^ = new C(x)
3333
val boxed2 : Observe[C]^ = box2(c) // error
34-
boxed2((cap: C^) => unsafe(c))
34+
boxed2((cap: C^) => unsafe(c)) // error
3535
0
3636

3737
trait File:

tests/neg-custom-args/captures/i15923.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ type Id[X] = [T] -> (op: X => T) -> T
33
def mkId[X](x: X): Id[X] = [T] => (op: X => T) => op(x)
44

55
def bar() = {
6-
def withCap[sealed X](op: (Cap^) => X): X = {
7-
val cap: Cap^ = new Cap { def use() = { println("cap is used"); 0 } }
6+
def withCap[X](op: (lcap: caps.Root) ?-> Cap^{lcap} => X): X = {
7+
val cap: Cap = new Cap { def use() = { println("cap is used"); 0 } }
88
val result = op(cap)
99
result
1010
}
1111

12-
val leak = withCap(cap => mkId(cap)) // error
12+
val leak = withCap(cap => mkId(cap)) // error // error
1313
leak { cap => cap.use() }
1414
}
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
-- Error: tests/neg-custom-args/captures/leaked-curried.scala:12:52 ----------------------------------------------------
2-
12 | val get: () ->{} () ->{io} Cap^ = () => () => io // error
3-
| ^^
4-
|(io : Cap^) cannot be referenced here; it is not included in the allowed capture set {} of pure base class trait Pure
1+
-- Error: tests/neg-custom-args/captures/leaked-curried.scala:13:20 ----------------------------------------------------
2+
13 | () => () => io // error
3+
| ^^
4+
|(io : Cap^{cap[main]}) cannot be referenced here; it is not included in the allowed capture set {} of pure base class trait Pure
5+
-- [E164] Declaration Error: tests/neg-custom-args/captures/leaked-curried.scala:12:10 ---------------------------------
6+
12 | val get: () ->{} () ->{io} Cap^ = // error
7+
| ^
8+
| error overriding value get in trait Box of type () -> () ->{cap[Box]} Cap^{cap[Box]};
9+
| value get of type () -> () ->{io} Cap^ has incompatible type
10+
|
11+
| longer explanation available when compiling with `-explain`
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
trait Cap:
22
def use(): Unit
33

4-
def withCap[sealed T](op: (x: Cap^) => T): T = ???
4+
def withCap[T](op: (x: Cap^) => T): T = ???
55

66
trait Box:
77
val get: () ->{} () ->{cap} Cap^
88

99
def main(): Unit =
1010
val leaked = withCap: (io: Cap^) =>
1111
class Foo extends Box, Pure:
12-
val get: () ->{} () ->{io} Cap^ = () => () => io // error
12+
val get: () ->{} () ->{io} Cap^ = // error
13+
() => () => io // error
1314
new Foo
1415
val bad = leaked.get()().use() // using a leaked capability

tests/neg-custom-args/captures/refs.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,35 @@ class Ref[T](init: T):
44
var x: T = init
55
def setX(x: T): Unit = this.x = x
66

7-
def usingLogFile[sealed T](op: FileOutputStream^ => T): T =
7+
def usingLogFile[T](op: (local: caps.Root) ?-> FileOutputStream^{local} => T): T =
88
val logFile = FileOutputStream("log")
99
val result = op(logFile)
1010
logFile.close()
1111
result
1212

1313
type Proc = () => Unit
1414
def test1 =
15-
usingLogFile[Proc]: f => // error
16-
() =>
17-
f.write(1)
18-
()
15+
usingLogFile[Proc]: (local: caps.Root) ?=> // error (but with a hard to parse error message)
16+
(f: FileOutputStream^{local}) =>
17+
() => f.write(1) // this line has type () ->{local} Unit, but usingLogFile
18+
// requires Proc, which expands to () -> 'cap[..test1](from instantiating usingLogFile)
1919

2020
def test2 =
2121
val r = new Ref[Proc](() => ())
2222
usingLogFile[Unit]: f =>
23-
r.setX(() => f.write(10)) // should be error
23+
r.setX(() => f.write(10)) // error
2424
r.x() // crash: f is closed at that point
2525

2626
def test3 =
2727
val r = new Ref[Proc](() => ())
2828
usingLogFile[Unit]: f =>
29-
r.x = () => f.write(10) // should be error
29+
r.x = () => f.write(10) // error
3030
r.x() // crash: f is closed at that point
3131

3232
def test4 =
33-
var r: Proc = () => () // error
33+
var r: Proc = () => ()
3434
usingLogFile[Unit]: f =>
35-
r = () => f.write(10)
35+
r = () => f.write(10) // error
3636
r() // crash: f is closed at that point
3737

3838

tests/neg-custom-args/captures/sealed-leaks.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import java.io.*
33
def Test2 =
44

5-
def usingLogFile[sealed T](op: FileOutputStream^ => T): T =
5+
def usingLogFile[T](op: (l: caps.Root) ?-> FileOutputStream^{l} => T): T =
66
val logFile = FileOutputStream("log")
77
val result = op(logFile)
88
logFile.close()
@@ -11,10 +11,10 @@ def Test2 =
1111
val later = usingLogFile { f => () => f.write(0) } // error
1212
val later2 = usingLogFile[(() => Unit) | Null] { f => () => f.write(0) } // error
1313

14-
var x: (FileOutputStream^) | Null = null // error
14+
var x: (FileOutputStream^) | Null = null
1515
def foo(f: FileOutputStream^, g: FileOutputStream^) =
1616
var y = if ??? then f else g // error
1717

18-
usingLogFile { f => x = f }
18+
usingLogFile { f => x = f } // error
1919

2020
later()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/simple-escapes.scala:16:10 -------------------------------
2+
16 | foo = f // error
3+
| ^
4+
| Found: box FileOutputStream^{f}
5+
| Required: box FileOutputStream^{cap[Test1]}
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- Error: tests/neg-custom-args/captures/simple-escapes.scala:19:15 ----------------------------------------------------
9+
19 | val later2 = usingLogFile { local => f => // error
10+
| ^^^^^^^^^^^^
11+
| escaping local reference local.type
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class FileOutputStream(str: String):
2+
def close(): Unit = ()
3+
def write(x: Int): Unit = ()
4+
5+
def Test1 =
6+
7+
def usingLogFile[T](op: (local: caps.Root) -> FileOutputStream^{local} => T): T =
8+
val logFile = FileOutputStream("log")
9+
val result = op(caps.cap)(logFile)
10+
logFile.close()
11+
result
12+
13+
var foo: FileOutputStream^ = FileOutputStream("")
14+
15+
val later1 = usingLogFile { local => f =>
16+
foo = f // error
17+
() => ()
18+
}
19+
val later2 = usingLogFile { local => f => // error
20+
() => f.write(0)
21+
}
22+
later1()
23+
later2()
24+

tests/neg-custom-args/captures/stack-alloc.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Pooled
55
val stack = mutable.ArrayBuffer[Pooled]()
66
var nextFree = 0
77

8-
def withFreshPooled[sealed T](op: Pooled^ => T): T =
8+
def withFreshPooled[T](op: (lcap: caps.Root) ?-> Pooled^{lcap} => T): T =
99
if nextFree >= stack.size then stack.append(new Pooled)
1010
val pooled = stack(nextFree)
1111
nextFree = nextFree + 1

tests/neg-custom-args/captures/usingLogFile.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import annotation.capability
33

44
object Test1:
55

6-
def usingLogFile[sealed T](op: FileOutputStream => T): T =
6+
def usingLogFile[T](op: (local: caps.Root) ?-> FileOutputStream => T): T =
77
val logFile = FileOutputStream("log")
88
val result = op(logFile)
99
logFile.close()
@@ -14,7 +14,7 @@ object Test1:
1414

1515
object Test2:
1616

17-
def usingLogFile[sealed T](op: FileOutputStream^ => T): T =
17+
def usingLogFile[T](op: (local: caps.Root) ?-> FileOutputStream^{local} => T): T =
1818
val logFile = FileOutputStream("log")
1919
val result = op(logFile)
2020
logFile.close()
@@ -38,7 +38,7 @@ object Test2:
3838

3939
object Test3:
4040

41-
def usingLogFile[sealed T](op: FileOutputStream^ => T) =
41+
def usingLogFile[T](op: (local: caps.Root) ?-> FileOutputStream^{local} => T) =
4242
val logFile = FileOutputStream("log")
4343
val result = op(logFile)
4444
logFile.close()
@@ -50,7 +50,7 @@ object Test4:
5050
class Logger(f: OutputStream^):
5151
def log(msg: String): Unit = ???
5252

53-
def usingFile[sealed T](name: String, op: OutputStream^ => T): T =
53+
def usingFile[T](name: String, op: (local: caps.Root) ?-> OutputStream^{local} => T): T =
5454
val f = new FileOutputStream(name)
5555
val result = op(f)
5656
f.close()
@@ -63,7 +63,7 @@ object Test4:
6363
later(1)
6464

6565

66-
def usingLogger[sealed T](f: OutputStream^, op: Logger^{f} => T): T =
66+
def usingLogger[T](f: OutputStream^, op: (local: caps.Root) ?-> Logger^{f} => T): T =
6767
val logger = Logger(f)
6868
op(logger)
6969

tests/neg-custom-args/captures/vars.scala

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@ def test(cap1: Cap, cap2: Cap) =
99
val zc: () ->{cap1} String = z
1010
val z2 = () => { x = identity }
1111
val z2c: () -> Unit = z2 // error
12+
var a: String => String = f
1213

13-
var a: String => String = f // error
14-
var b: List[String => String] = Nil // error
14+
var b: List[String => String] = Nil
1515
val u = a // was error, now ok
1616
a("") // was error, now ok
1717
b.head // was error, now ok
1818

1919
def scope =
2020
val cap3: Cap = CC()
2121
def g(x: String): String = if cap3 == cap3 then "" else "a"
22-
a = g
23-
b = List(g)
22+
def h(): String = ""
23+
a = x => g(x) // error
24+
a = g // error
25+
26+
b = List(g) // error
2427
val gc = g
2528
g
2629

27-
val s = scope
28-
val sc: String => String = scope
30+
val s = scope // error (but should be OK, we need to allow poly-captures)
31+
val sc: String => String = scope // error (but should also be OK)
2932

30-
def local[sealed T](op: Cap -> T): T = op(CC())
33+
def local[T](op: (local: caps.Root) -> CC^{local} -> T): T = op(caps.cap)(CC())
3134

32-
local { cap3 => // error
35+
local { root => cap3 => // error
3336
def g(x: String): String = if cap3 == cap3 then "" else "a"
3437
g
3538
}
@@ -39,4 +42,4 @@ def test(cap1: Cap, cap2: Cap) =
3942

4043
val r = Ref()
4144
r.elem = f
42-
val fc = r.elem
45+
val fc = r.elem

0 commit comments

Comments
 (0)