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

Incorrect captures for interface operations with block parameters #603

Open marzipankaiser opened 2 months ago

marzipankaiser commented 2 months ago

In the following example, the captures are annotated as indicated in the comments:

interface Bar {
  def bar(): Unit
}
interface Foo {
  def foo(){b: Bar}: Unit
}

// {b}
def baz() = {
  // {b}
  def x = new Foo { 
    def foo(){b} = { b.bar() }
  }
  // {}
  def b2 = new Bar { def bar() = () }
  x.foo{b2}
}

// {}
def foof(){b: Bar} = b.bar()

// {b}
def main() = {
  baz()
}

Here, the capture for x contains b, which is not even in scope outside of the definition of foo. (This is also inconsistent with the captures of foof).

marzipankaiser commented 2 months ago

I think we need to add the captures for block parameters here (not just the capabilities from effects), so we remove them in the result: https://github.com/effekt-lang/effekt/blob/e0e5c60e3fdda4dbc693207a776ae60f41b0d292/effekt/shared/src/main/scala/effekt/Typer.scala#L437-L445

b-studios commented 2 months ago

Yes, that sounds about right

jiribenes commented 2 months ago

I'll mark this as a good first issue, since it's pretty understandable and the solution should be straightforward. However, if this actually blocks someone's flow, feel free to do it sooner/yourself without waiting for the Hackathon :)