If I use this compiler option:
-language:experimental.captureChecking
the following code doesn’t compile:
import scala.collection.mutable.ListBuffer
open class MyItem
open class MyContainer[T <: MyItem]:
private val consumers = ListBuffer.empty[T => Unit]
the message is:
Sealed type variable A cannot be instantiated to box T => Unit since
that type captures the root capabilitycap
.
This is often caused by a local capability in an argument of method empty
leaking as part of its result.
I perfectly understand that the feature is experimental but I am genuinely curious if it’s just a case of it being “too experimental for practical usage” or maybe I am doing something conceptually wrong.