forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix setup of CapSet arguments. (scala#21309)
These arguments tell the whole truth; they cannot possibly be decorated with another capture set. So we should not add a capture set variable.
- Loading branch information
Showing
12 changed files
with
143 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- Error: tests/neg-custom-args/captures/i21313.scala:6:27 ------------------------------------------------------------- | ||
6 |def foo(x: Async) = x.await(???) // error | ||
| ^ | ||
| (x : Async) is not a tracked capability | ||
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21313.scala:15:12 --------------------------------------- | ||
15 | ac1.await(src2) // error | ||
| ^^^^ | ||
| Found: (src2 : Source[Int, caps.CapSet^{ac2}]^?) | ||
| Required: Source[Int, caps.CapSet^{ac1}]^ | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import caps.CapSet | ||
|
||
trait Async: | ||
def await[T, Cap^](using caps.Contains[Cap, this.type])(src: Source[T, Cap]^): T | ||
|
||
def foo(x: Async) = x.await(???) // error | ||
|
||
trait Source[+T, Cap^]: | ||
final def await(using ac: Async^{Cap^}) = ac.await[T, Cap](this) // Contains[Cap, ac] is assured because {ac} <: Cap. | ||
|
||
def test(using ac1: Async^, ac2: Async^, x: String) = | ||
val src1 = new Source[Int, CapSet^{ac1}] {} | ||
ac1.await(src1) // ok | ||
val src2 = new Source[Int, CapSet^{ac2}] {} | ||
ac1.await(src2) // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- Error: tests/neg-custom-args/captures/i21347.scala:4:15 ------------------------------------------------------------- | ||
4 | ops.foreach: op => // error | ||
| ^ | ||
| Local reach capability C leaks into capture scope of method runOps | ||
5 | op() | ||
-- Error: tests/neg-custom-args/captures/i21347.scala:8:14 ------------------------------------------------------------- | ||
8 | () => runOps(f :: Nil) // error | ||
| ^^^^^^^^^^^^^^^^ | ||
| reference (caps.cap : caps.Capability) is not included in the allowed capture set {} | ||
| of an enclosing function literal with expected type () -> Unit | ||
-- Error: tests/neg-custom-args/captures/i21347.scala:11:15 ------------------------------------------------------------ | ||
11 | ops.foreach: op => // error | ||
| ^ | ||
| Local reach capability ops* leaks into capture scope of method runOpsAlt | ||
12 | op() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import language.experimental.captureChecking | ||
|
||
def runOps[C^](ops: List[() ->{C^} Unit]): Unit = | ||
ops.foreach: op => // error | ||
op() | ||
|
||
def boom(f: () => Unit): () -> Unit = | ||
() => runOps(f :: Nil) // error | ||
|
||
def runOpsAlt(ops: List[() => Unit]): Unit = | ||
ops.foreach: op => // error | ||
op() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import caps.CapSet | ||
|
||
trait Async: | ||
def await[T, Cap^](using caps.Contains[Cap, this.type])(src: Source[T, Cap]^): T | ||
|
||
trait Source[+T, Cap^]: | ||
final def await(using ac: Async^{Cap^}) = ac.await[T, Cap](this) // Contains[Cap, ac] is assured because {ac} <: Cap. | ||
|
||
def test(using ac1: Async^, ac2: Async^, x: String) = | ||
val src1 = new Source[Int, CapSet^{ac1}] {} | ||
ac1.await(src1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import language.experimental.captureChecking | ||
|
||
class Source[+T, Cap^] | ||
|
||
def completed[T, Cap^](result: T): Source[T, Cap] = | ||
//val fut = new Source[T, Cap]() | ||
val fut2 = new Source[T, Cap]() | ||
fut2: Source[T, Cap] | ||
|
||
|
||
|
||
|
||
|
||
|