-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Need a way to require a particular capability to be in a capture set #21313
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
Comments
I couldn't see the reason why the Cap of Source has to contain Source.this. Async.await requires its capture argument at least contains Async.this, which is async.this in this case. Given that we have async: Async^{Cap^}, ideally we should be able to show that Async.this <: {Cap^}, and thus pass the subtype check? |
@Linyxus In fact yes, the error message is misleading.
should be
I believe a substitution or asSeenFrom was not done correctly here in the annotation at Typer, which is when the error was issued. But the problem remains: we can't assure the lower bound in The variant with 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^})(using caps.Contains[Cap, ac]) = ac.await[T, Cap](this)``` |
I believe by Contains[Cap, ac] we are asking for the constraint {ac} <: {Cap^}. But, given that ac: Async^{Cap^}, wouldn't {ac} <: {Cap^} already hold? |
Good point. We need to verify that. But the original problem is elsewhere. We can't have a lower bound 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^}) = ac.await[T, Cap](this) // Contains[Cap, ac] is assured because {ac} <: Cap. |
With trait Async:
def await[T, Cap^: Contains[this]])(src: Source[T, Cap]^): T Then it looks nicer. |
The idea for given Contains[C <: CapSet^, R <: Singleton]() So Contains[Cs, ref.type] check that |
I agree, this looks good! |
Fixed by #21361 |
Minimized example
The following attempt to link capabilities of Async contexts and sources fails.
The error makes sense. What we'd need to assert is that also
Source.this
is in theCap^
parameter ofSource
. But we can't express this with a lower bound. This fails: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:
The text was updated successfully, but these errors were encountered: