Open
Description
Minimized Example
//> using scala 3.6.0-RC1-bin-SNAPSHOT
import language.experimental.captureChecking
import scala.collection.mutable
abstract class Future[T, Cap^] :
def complete(res: T): Unit // allow `complete` to charge `Cap` to the environment?
def f[T, Cap^](): Future[T, Cap]^{Cap^} = new Future[T, Cap]:
val set: mutable.Set[(T -> Unit)^{Cap^}] = mutable.Set[(T -> Unit)^{Cap^}]()
override def complete(res: T) = set.foreach(_(res))
complete
cannot be overridden in f
, since it charges the reach capability of set
(which is Cap
) to the environment.
12 | override def complete(res: T) = set.foreach(_(res))
| ^^^^^^
| Local reach capability Cap leaks into capture scope of method f
While this is correct to be rejected, there is no way to relax this restriction; there are no syntax to specify in Future
that complete
may charge Cap
.