You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importlanguage.experimental.captureCheckingimportscala.collection.mutable.ListBufferclassMyContainer:privatevalconsumers=ListBuffer.empty[() =>Unit]
privatedefexecute():Unit=for consumer <- consumers do
consumer()
// ... which, is equivalent to ...privatedefexecuteAlt():Unit=
consumers.foreach: (f: () =>Unit) =>
f()
Output
-- [E007] TypeMismatchError: errmsg.scala:9:8--------------------------------9|for consumer <- consumers do| ^
|Found: (consumer: () =>Unit) ->?Unit|Required: (consumer: box () =>Unit) -><fluid> Unit||Note that () =>Unit cannot be box-converted to box () =>Unit|since at least one of their capture sets contains the root capability `cap`
10| consumer()
|| longer explanation available when compiling with`-explain`-- [E007] TypeMismatchError: errmsg.scala:15:23------------------------------15| consumers.foreach: (f: () =>Unit) =>| ^
|Found: (f: () =>Unit) ->?Unit|Required: (f: box () =>Unit) -><fluid> Unit||Note that () =>Unit cannot be box-converted to box () =>Unit|since at least one of their capture sets contains the root capability `cap`
16| f()
|| longer explanation available when compiling with`-explain`2 errors found
Expectation
The crux of this error is that ListBuffer[box () => Unit] is mutable and therefore the type argument box () => Unit is invariant. Reach refinement is impossible, and the attempt to unbox its elements results in a box conversion error.
The text was updated successfully, but these errors were encountered:
I am assuming that we do want to hide boxes completely from the user. In other words, boxes are internal constructs, and only for those who really curious about what is under the hood are details of boxes relevant.
The problem then becomes how these boxing errors can be translated to human-readable messages. It feels that the only thing that these boxing errors are really talking about is simply "scope violation". And it seems to be at least two kinds of scope violation issues:
Functions returning unnamable capabilities
Mutable states containing unnamable capabilities
Note that the second category extends beyond var definitions. For instance, this issue falls in this second category as well.
It will be interesting to see whether this two scenarios can be detected, and errors be emitted in a more human-readable manner than the status quo.
Compiler version
main
Minimized code
Output
Expectation
The crux of this error is that
ListBuffer[box () => Unit]
is mutable and therefore the type argumentbox () => Unit
is invariant. Reach refinement is impossible, and the attempt to unbox its elements results in a box conversion error.The text was updated successfully, but these errors were encountered: