effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Unhelpful error message when boxing blocks

Open jiribenes opened this issue 2 years ago • 4 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: Screenshot 2024-01-12 at 17 52 30

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)
}

returns: Screenshot 2024-01-12 at 17 51 07

jiribenes avatar Jan 12 '24 16:01 jiribenes

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

b-studios avatar Jan 13 '24 09:01 b-studios

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.

jiribenes avatar Jan 13 '24 09:01 jiribenes

Update: the error is slightly different now (unfortunately still unhelpful though...) Screenshot 2024-06-04 at 14 00 05

jiribenes avatar Jun 04 '24 12:06 jiribenes