Open
Description
Compiler version
cc-experiment
branch
Minimized code
trait Cap { def use(): Int }
type Id[X] = [T] -> (op: X => T) -> T
def mkId[X](x: X): Id[X] = [T] => (op: X => T) => op(x)
def bar() = {
def withCap[X](op: ({*} Cap) => X): X = {
val cap: {*} Cap = new Cap { def use() = { println("cap is used"); 0 } }
val result = op(cap)
result
}
val leak = withCap(cap => mkId(cap))
leak { cap => cap.use() } // bad
}
Output
It compiles.
Expectation
It should not compile. We expect the type of val leak
to be Id[□ {*} Cap]
, so it will expect a function of (□ {*} Cap) => Unit
in leak(...)
. It will not be possible to adapt cap => cap.use() : ({*} Cap) -> Unit
to the type (□ {*} Cap) => Unit
since the adaption cap => (unbox cap).use()
tries to unbox a reference capturing universal capability.
We should issue an error on leak(...)
.