Skip to content

Need a way to require a particular capability to be in a capture set #21313

Closed
@odersky

Description

@odersky

Minimized example

The following attempt to link capabilities of Async contexts and sources fails.

import language.experimental.captureChecking
import caps.{Capability, CapSet}

trait Async:
  def await[T, Cap >: CapSet^{this} <: CapSet^](src: Source[T, Cap]^): T

trait Source[+T, Cap^]:
  final def await(using ac: Async^{Cap^}) = ac.await[T, Cap](this)```
    // error: Type argument Cap does not conform to lower bound caps.CapSet^{this}

The error makes sense. What we'd need to assert is that also Source.this is in the Cap^ parameter of Source. But we can't express this with a lower bound. This fails:

trait Source[+T, Cap >: CapSet^{this} <: CapSet^]: // error: illegal occurrence of Source.this

Indeed the this of a class cannot be used in the bounds of the class parameters.

I believe we should look for a different way to express this. Maybe a magic type class, caps.Contains?
Something along the lines of:

trait Async:
  def await[T, Cap^](using caps.Contains[Cap, this])(src: Source[T, Cap]^): T

trait Source[+T, Cap^]:
  final def await(using ac: Async^{Cap^}, _: caps.Contains[Cap, this]) = ac.await[T, Cap](this)```
    // error: Type argument Cap does not conform to lower bound caps.CapSet^{this}```

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions