effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism
https://effekt-lang.org
MIT License
334 stars 24 forks source link

Field access fails after unboxing with a local binding #673

Closed jiribenes closed 2 weeks ago

jiribenes commented 2 weeks ago

On both the website and my local installation (Effekt v0.8.0), the following code returns what seems like a compiler panic:

Minimised repro:

record Container(eqz: (Int) => Bool at {})

def ap(c: Container, k: Int): Bool = {
  def eqz = unbox c.eqz // You can delete the explicit `unbox`, it's just here for clarity
  c.eqz(k)
// ~^^^ Error: Not a valid method or function: eqz4041
}

Of course, you can fix this by calling eqz (the local binding) instead. Otherwise this is very reminiscent of #635.

Funnily enough, it's somewhat random where exactly the error appears in the editor.

As a note, I haven't yet tried it on the current master with #671 merged.

A similar issue happens even if we try to bind the same thing twice:

record Container(eqz: (Int) => Bool at {})

def ap2(c: Container, k: Int): Bool = {
  def eqz = unbox c.eqz
  def second = unbox c.eqz // both `unbox`es are just for clarity
  second(42) // Same error as above: "Not a valid method or function: eqz4256"
}

Relevant code: https://github.com/effekt-lang/effekt/blob/dc9149737c9d713ce04a26591d77d8cdfccf50e7/effekt/shared/src/main/scala/effekt/typer/BoxUnboxInference.scala#L86-L100

b-studios commented 2 weeks ago

This is the situation on current master:

image

This works:

def ap(c: Container, k: Int): Bool = {
  (c.eqz)(k)
}
b-studios commented 2 weeks ago

I'll close this for now, since I don't know a better solution and box/unbox might need to be redesigned anyway.

Feel free to open again if you disagree.

jiribenes commented 2 weeks ago

I can confirm that even the ap2 function works on current master, so the issue is truly resolved :)