Scala 3.5.1 compilation issue with captureChecking turned on

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 capability cap.
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.

It’s probably a bug that was fixed already in the main. It still fails in 3.5.2-RC1, but compiles in latest nightly: 3.6.0-RC1-bin-20240926-eb5c3e8-NIGHTLY

1 Like

I see, thank you very much @WojciechMazur !