effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Structural equality on JavaScript backend doesn't work

Open jiribenes opened this issue 11 months ago • 1 comments

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
}

jiribenes avatar Mar 22 '24 15:03 jiribenes

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:

  1. the first "layer" structurally
  2. the other layer just based on JavaScript's === equality

jiribenes avatar Mar 22 '24 16:03 jiribenes

One should call this: https://github.com/effekt-lang/effekt/blob/3e38409948d94ad5c30e3769d7fc41ae7d91a9ea/libraries/js/effekt_builtins.js#L13

jiribenes avatar Jun 13 '24 09:06 jiribenes