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

0 commit comments

Comments
 (0)