Skip to content

Commit 5d0eb54

Browse files
committed
Add Id example to reaches neg test
1 parent d3900df commit 5d0eb54

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:22:11 --------------------------------------
2+
22 | cur = (() => f.write()) :: Nil // error since {f*} !<: {xs*}
3+
| ^^^^^^^^^^^^^^^^^^^^^^^
4+
| Found: List[box () ->{f} Unit]
5+
| Required: List[box () ->{xs*} Unit]
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:33:7 ---------------------------------------
9+
33 | (() => f.write()) :: Nil // error since {f*} !<: {xs*}
10+
| ^^^^^^^^^^^^^^^^^^^^^^^
11+
| Found: List[box () ->{f} Unit]
12+
| Required: box List[box () ->{xs*} Unit]^?
13+
|
14+
| Note that reference (f : File^), defined in method $anonfun
15+
| cannot be included in outer capture set {xs*} of value cur which is associated with method runAll1
16+
|
17+
| longer explanation available when compiling with `-explain`
18+
-- Error: tests/neg-custom-args/captures/reaches.scala:36:6 ------------------------------------------------------------
19+
36 | var cur: List[Proc] = xs // error: Illegal type for var
20+
| ^
21+
| Mutable variable cur cannot have type List[box () => Unit] since
22+
| the part box () => Unit of that type captures the root capability `cap`.
23+
-- Error: tests/neg-custom-args/captures/reaches.scala:43:15 -----------------------------------------------------------
24+
43 | val cur = Ref[List[Proc]](xs) // error: illegal type for type argument to Ref
25+
| ^^^^^^^^^^^^^^^
26+
| Sealed type variable T cannot be instantiated to List[box () => Unit] since
27+
| the part box () => Unit of that type captures the root capability `cap`.
28+
| This is often caused by a local capability in an argument of constructor Ref
29+
| leaking as part of its result.
30+
-- Error: tests/neg-custom-args/captures/reaches.scala:53:31 -----------------------------------------------------------
31+
53 | val id: Id[Proc, Proc] = new Id[Proc, () -> Unit] // error
32+
| ^^^^^^^^^^^^^^^^^^^^
33+
| Sealed type variable A cannot be instantiated to box () => Unit since
34+
| that type captures the root capability `cap`.
35+
| This is often caused by a local capability in an argument of constructor Id
36+
| leaking as part of its result.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ def runAll3(xs: List[Proc]): Unit =
4646
next()
4747
cur.set(cur.get.tail: List[Proc])
4848

49+
class Id[sealed -A, sealed +B >: A]():
50+
def apply(a: A): B = a
51+
52+
def test =
53+
val id: Id[Proc, Proc] = new Id[Proc, () -> Unit] // error
54+
usingFile: f =>
55+
id(() => f.write()) // escape, if it was not for the error above

0 commit comments

Comments
 (0)