Unable to import and use a namespaced effect because of escaping its lexical scope
jiribenes opened this issue · comments
This bug was originally discovered when attempting to use the network
library from #432, but the bug is independent of that PR.
The issue requires two files to reproduce:
module mystate
namespace internal {
interface State {
def get(): Int
def set(a: Int): Unit
}
def withState[R](a: Int) { prog: => R / State }: R = {
var ref = a
try { prog() }
with State {
def get() = resume(ref)
def set(a: Int) = {
ref = a
resume(())
}
}
}
}
module other
import mystate
def foo(): Unit / internal::State = {
val n = do internal::get()
do internal::set(n + 42)
}
The compiler is very dissatisfied with this function and reports the following error:
Effect State leaves its defining lexical scope as part of the inferred type
However, if you inline the mystate
directly, no error is reported and everything works!