Skip to content

Commit ff52a47

Browse files
authored
Rewrite reaches tests to fix tasty-cc nightly failures (#20156)
The reaches.scala pos test failed the nightly with tasty cc since one line violated the new condition for reaches capabilities. The problem was not discoveed in normal testing since it used the `List` class, which is capture checked only in the nightly. We now make the relevant bits of `List` explicit in the test itself, so that it is always capture checked. The failing line got moved to neg. [test_scala2_library_tasty]
2 parents 1fa158b + db529d9 commit ff52a47

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@
4141
| Required: File^{id*}
4242
|
4343
| longer explanation available when compiling with `-explain`
44+
-- Error: tests/neg-custom-args/captures/reaches.scala:77:5 ------------------------------------------------------------
45+
77 | ps.map((x, y) => compose1(x, y)) // error: cannot mix cap and *
46+
| ^^^^^^
47+
| Reach capability cap and universal capability cap cannot both
48+
| appear in the type [B](f: ((box A ->{ps*} A, box A ->{ps*} A)) => B): List[B] of this expression

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,21 @@ def attack2 =
5959
val leaked = usingFile[File^{id*}]: f =>
6060
val f1: File^{id*} = id(f) // error
6161
f1
62+
63+
class List[+A]:
64+
def head: A = ???
65+
def tail: List[A] = ???
66+
def map[B](f: A => B): List[B] = ???
67+
def nonEmpty: Boolean = ???
68+
69+
extension [A](x: A) def :: (xs: List[A]): List[A] = ???
70+
71+
object Nil extends List[Nothing]
72+
73+
def compose1[A, B, C](f: A => B, g: B => C): A ->{f, g} C =
74+
z => g(f(z))
75+
76+
def mapCompose[A](ps: List[(A => A, A => A)]): List[A ->{ps*} A] =
77+
ps.map((x, y) => compose1(x, y)) // error: cannot mix cap and *
78+
79+

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ class Ref[T](init: T):
1010
def get: T = x
1111
def set(y: T) = { x = y }
1212

13+
class List[+A]:
14+
def head: A = ???
15+
def tail: List[A] = ???
16+
def map[B](f: A -> B): List[B] = ???
17+
def nonEmpty: Boolean = ???
18+
19+
extension [A](x: A) def :: (xs: List[A]): List[A] = ???
20+
21+
object Nil extends List[Nothing]
22+
1323
def runAll(xs: List[Proc]): Unit =
1424
var cur: List[() ->{xs*} Unit] = xs // OK, by revised VAR
1525
while cur.nonEmpty do
@@ -36,7 +46,7 @@ def compose2[A, B, C](f: A => B, g: B => C): A => C =
3646
z => g(f(z))
3747

3848
def mapCompose[A](ps: List[(A => A, A => A)]): List[A ->{ps*} A] =
39-
ps.map((x, y) => compose1(x, y))
49+
ps.map((x, y) => compose1(x, y)) // Does not work if map takes an impure function, see reaches in neg
4050

4151
@annotation.capability class IO
4252

0 commit comments

Comments
 (0)