Unhelpful error message when boxing blocks
jiribenes opened this issue · comments
The motivation is wrapping a block into a box in order to facilitate a nicer API. (using orElse { ... } { ... }
instead of orElse(box { ... }, box { ... }
).
I don't quite know whether this is just a bad error message or if it's an actual bug in Typer:
Here's the offending code:
interface OrElse {
def orElse[T](m1: => T / {} at {}, m2: => T / {} at {}): T
}
def orElse[T] { m1: => T / {} }{ m2: => T / {} }: T / {OrElse} = {
do orElse(box { m1 }, box { m2 })
}
which returns the following unhelpful message:
If I just ANF it, I get the same message. When I remove the braces, I get a different error:
interface OrElse {
def orElse[T](m1: => T / {} at {}, m2: => T / {} at {}): T
}
def orElse[T] { m1: => T / {} }{ m2: => T / {} }: T / {OrElse} = {
val f1 = box m1;
val f2 = box m2;
do orElse(f1, f2)
}
I think there are a few different issues here. The first error message is indeed confusing.
However, the second message is expected: you are passing f1
which has capture m1
to the operation which requires an empty capture set.
On a high level: I deeply understand the motivation of avoiding box in the API but I think it's not possible this way.
Maybe we can make it more lightweight by changing syntax somehow
On a high level: I deeply understand the motivation of avoiding box in the API but I think it's not possible this way.
I thought so, but I still wanted to report the confusing error message — dealing with boxing and captures is difficult already.