Currently, Scala capture checking silently drops capture set from primitive types.
Example:
import language.experimental.captureChecking
import caps.*
class Box(val value: String)
val cap1: SharedCapability^ = ???
def extract[T](x: List[T]): T^{cap1} = ???
// Box: capability is preserved
def testBox(): Unit =
val x = extract(List(Box("hello")))
val y: Box = x // error
// String: capability is silently dropped
def testString(): Unit =
val x = extract(List("hello"))
val y: String = x // no error, but should be
On one side, it’s understandable when capturing tracking a ‘real value in closure’ than primitives shoule be excluded.
But we can have virtual properties that are usually described by phantom types.
An example is security analysis: are we receiving this string from trusted sources?
And analysis basically the same as capture tracking – we bind the property to the value (i.e. add property {is-untrusted/trusted}, depends from type of analysis, in the capture-set)
So, question - is it possible to define a marker trait for the Cap, which will not drop on primitive types?