Compiler crash on showing record accessors
jiribenes opened this issue · comments
Jiří Beneš commented
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
:
If I had to guess, there's a miscompilation somewhere when handling accessors as functions:
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.)