scala3
scala3 copied to clipboard
`A ?->{cap} B` is not a synonym behaviorally of `A ?=> B`
Compiler version
3.4.0
Minimized code
trait Ptr[A]
@capability trait Scope:
def allocate(size: Int): Ptr[Unit]^{this}
object Scope:
def confined[A](fn: Scope ?->{cap} A): A =
val scope = new Scope:
def allocate(size: Int) = new Ptr[Unit] {}
fn(scope)
Output
Scala 3.4.0 treats A ?->{cap} B
as if it were a regular function rather than a context function, including downstream when you use it. using
parameters are not picked up (like in the above example), and context is missing without a pattern bound context like so:
val s = Scope.confined{ case given Scope =>
val s2 = summon[Scope]
Scope.confined{ case given Scope =>
s2.allocate(5)
}
5
}
Expectation
I expected the pure version of a context function with specificied captures to work like the impure version A ?=> B.