Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite reaches tests to fix tasty-cc nightly failures #20156

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/neg-custom-args/captures/reaches.check
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@
| Required: File^{id*}
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-custom-args/captures/reaches.scala:77:5 ------------------------------------------------------------
77 | ps.map((x, y) => compose1(x, y)) // error: cannot mix cap and *
| ^^^^^^
| Reach capability cap and universal capability cap cannot both
| appear in the type [B](f: ((box A ->{ps*} A, box A ->{ps*} A)) => B): List[B] of this expression
18 changes: 18 additions & 0 deletions tests/neg-custom-args/captures/reaches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,21 @@ def attack2 =
val leaked = usingFile[File^{id*}]: f =>
val f1: File^{id*} = id(f) // error
f1

class List[+A]:
def head: A = ???
def tail: List[A] = ???
def map[B](f: A => B): List[B] = ???
def nonEmpty: Boolean = ???

extension [A](x: A) def :: (xs: List[A]): List[A] = ???

object Nil extends List[Nothing]

def compose1[A, B, C](f: A => B, g: B => C): A ->{f, g} C =
z => g(f(z))

def mapCompose[A](ps: List[(A => A, A => A)]): List[A ->{ps*} A] =
ps.map((x, y) => compose1(x, y)) // error: cannot mix cap and *


12 changes: 11 additions & 1 deletion tests/pos-custom-args/captures/reaches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ class Ref[T](init: T):
def get: T = x
def set(y: T) = { x = y }

class List[+A]:
def head: A = ???
def tail: List[A] = ???
def map[B](f: A -> B): List[B] = ???
def nonEmpty: Boolean = ???

extension [A](x: A) def :: (xs: List[A]): List[A] = ???

object Nil extends List[Nothing]

def runAll(xs: List[Proc]): Unit =
var cur: List[() ->{xs*} Unit] = xs // OK, by revised VAR
while cur.nonEmpty do
Expand All @@ -36,7 +46,7 @@ def compose2[A, B, C](f: A => B, g: B => C): A => C =
z => g(f(z))

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

@annotation.capability class IO

Expand Down
Loading