effekt-lang / effekt

A language with lexical effect handlers and lightweight effect polymorphism

Home Page:https://effekt-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiler crash on showing record accessors

jiribenes opened this issue · comments

When compiling the following program for the JavaScript (node) backend:

record Person(id: Int)

def main() = {
  println(id.show)
}

I get a compiler crash with:

ReferenceError: Can't find variable: id_1653

This is a bit difficult since we do allow functions to be printed using show:
Screenshot 2023-12-04 at 14 08 10

If I had to guess, there's a miscompilation somewhere when handling accessors as functions:
Screenshot 2023-12-04 at 14 09 18

as witnessed in the REPL when asking about the type of foo:

> record R(foo: Int)
> :t foo
R => Int at {}

A longer example which is a bit more "realistic":

record Person(id: Int)

def main() = {
  val people = [Person(1), Person(2)]

  people.foreach { p =>
    println("Person " ++ id.show)
  }
}

(There was a foreachIndex, but I didn't use its index and the println was commented out so I refactored it to foreach. Then I uncommented the println and got a compiler crash instead of an error message.)