effekt
effekt copied to clipboard
Structural equality on JavaScript backend doesn't work
The structural equality on the JavaScript backend seems to be broken.
Although reflexivity (x == x
) holds for simple, user-defined types, it doesn't work for Some(x) == Some(x)
.
type MyType {
MySingleCase()
}
record EmptyRecord()
def main() = {
println(MySingleCase() == MySingleCase()) // ~> true
println(EmptyRecord() == EmptyRecord()) // ~> true
println(Some(MySingleCase()) == Some(MySingleCase())) // ~> false
println(Some(EmptyRecord()) == Some(EmptyRecord())) // ~> false
}
https://github.com/effekt-lang/effekt/blob/a702e93e4cc5d67a69eca400f6c8bacb836ff557/effekt/shared/src/main/scala/effekt/generator/js/Transformer.scala#L52-L62
Line 54
is not correct, we should use equals$impl
or something similar here in order to recurse.
Currently, we compare:
- the first "layer" structurally
- the other layer just based on JavaScript's
===
equality
One should call this: https://github.com/effekt-lang/effekt/blob/3e38409948d94ad5c30e3769d7fc41ae7d91a9ea/libraries/js/effekt_builtins.js#L13