Hi!
I am using explicit capture polymorphism for a project heavily, and I am trying to use capture set type variables and self-type to define a type that captures something without storing it. As an example, something like this should work in my understanding of capture sets and self-type:
class A[CS^]:
self: A[CS^]^ =>
end A
@main def main(): Unit =
val a: A[{}]^ = A[{}] // should be `A[{cap}]` but the compiler didn't allow it
val b = A[{a}]
I am expecting the compiler to infer that A’s capture set will be its type argument CS^, but it looks like it’s not the case. The compiler output with “-Xprint:cc”
val a: A[scala.caps.CapSet]^ =
new ([CS >: scala.caps.CapSet <: scala.caps.CapSet^] =>> A[CS])[
scala.caps.CapSet]()
val b: A[scala.caps.CapSet^{a}]^{} =
new ([CS >: scala.caps.CapSet <: scala.caps.CapSet^] =>> A[CS])[
scala.caps.CapSet^{a}]()
As you can see, the capture sets are empty.
I was wondering:
- Is it a compiler bug, or am I not understanding something?
- Is using capture set type params this way an anti-pattern?
- Is the goal (of capturing something without storing it) possible without self-types?
Thanks