Should we be able to put root capability in type parameters of classes? #15059
abgruszecki
started this conversation in
CC experiment
Replies: 1 comment 1 reply
-
I think going to
type Proc = {*} () -> Unit
val xs: List[Proc] = ???
val x = xs.head gives
Now it's a separate question whether we should allow the formation of values of this type if there's not |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently CC experiment allows types like
List[{*} Proc]
, with my favorite aliastype Proc = Unit => Unit
. It seems to me such types should be rejected as ill-formed. The basic argument is that according to the formalism, all elements of such a list should be in an unopenable box. Since we don't have boxes in the surface syntax, the most reasonable thing to do seems to be simply forbidding such types.Even an immutable collection like
List
could be used to leak scoped capabilities if we can use{*} Proc
as its elements. Similarly, a mutable collection likeListBuffer[{*} Proc]
could be easily used to leak a scoped capability and use it outside of its scope.However, forbidding such types rules out the most natural way to migrate existing code to capture checking, i.e. simply putting
{*}
as the c.s. of every type. If we are concerned about this, perhaps we should introduce an annotation like@unsafeCap
that could be used to allow such types, as in:List[@unsafeCap {*} Proc]
?/cc @odersky
Beta Was this translation helpful? Give feedback.
All reactions