Skip to content

Some additions and changes in tests #17327

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

Merged
merged 1 commit into from
Apr 22, 2023
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
18 changes: 18 additions & 0 deletions tests/neg-custom-args/captures/filevar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import language.experimental.captureChecking
import compiletime.uninitialized

class File:
def write(x: String): Unit = ???

class Service:
var file: {*} File = uninitialized
def log = file.write("log") // error

def withFile[T](op: (f: {*} File) => T): T =
op(new File)

def test =
withFile: f =>
val o = Service()
o.file = f
o.log
10 changes: 10 additions & 0 deletions tests/pending/pos/i16826.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import language.experimental.captureChecking
class A
class B(a: {*} A)
class C(a: {*} A):
def setB(b: {a} B): Unit = ???


def test(a1: {*} A)(b1: {a1} B) =
val c = new C(a1)
c.setB(b1)
37 changes: 37 additions & 0 deletions tests/pos-custom-args/captures/filevar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import language.experimental.captureChecking
import annotation.capability
import compiletime.uninitialized

object test1:
class File:
def write(x: String): Unit = ???

class Service(f: {*} File):
def log = f.write("log")

def withFile[T](op: (f: {*} File) => T): T =
op(new File)

def test =
withFile: f =>
val o = Service(f)
o.log

object test2:
@capability class IO

class File:
def write(x: String): Unit = ???

class Service(io: IO):
var file: {io} File = uninitialized
def log = file.write("log")

def withFile[T](io: IO)(op: (f: {io} File) => T): T =
op(new File)

def test(io: IO) =
withFile(io): f =>
val o = Service(io)
o.file = f
o.log
21 changes: 21 additions & 0 deletions tests/pos-custom-args/captures/nested-classes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import language.experimental.captureChecking
import annotation.{capability, constructorOnly}

@capability class IO
class Blah
class Pkg(using @constructorOnly io: IO):
class Foo:
def m(foo: {io} Blah) = ???
class Pkg2(using io: IO):
class Foo:
def m(foo: {io} Blah): Any = io; ???

def main(using io: IO) =
val pkg = Pkg()
val f = pkg.Foo()
f.m(???)
val pkg2 = Pkg2()
val f2 = pkg2.Foo()
f2.m(???)


4 changes: 2 additions & 2 deletions tests/run/errorhandling/Result.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ object Result:
case err: Err[_] => err

/** Validate both `r` and `other`; return a pair of successes or a list of failures. */
def * [U](other: Result[U, E]): Result[(T, U), List[E]] = (r, other) match
def zip[U](other: Result[U, E]): Result[(T, U), List[E]] = (r, other) match
case (Ok(x), Ok(y)) => Ok((x, y))
case (Ok(_), Err(e)) => Err(e :: Nil)
case (Err(e), Ok(_)) => Err(e :: Nil)
case (Err(e1), Err(e2)) => Err(e1 :: e2 :: Nil)

/** Validate both `r` and `other`; return a tuple of successes or a list of failures.
* Unlike with `*`, the right hand side `other` must be a `Result` returning a `Tuple`,
* Unlike with `zip`, the right hand side `other` must be a `Result` returning a `Tuple`,
* and the left hand side is added to it. See `Result.empty` for a convenient
* right unit of chains of `*:`s.
*/
Expand Down