Fable: Regression: Hashing POJOs fails

Created on 19 Nov 2020  路  2Comments  路  Source: fable-compiler/Fable

Description

_This was reported by @tomcl in https://github.com/fable-compiler/Fable/issues/2277#issuecomment-730324828:_

The app used List.distinct on a JS object list. This broke under Fable3 as you can imagine. I used distinctBy and a string id to mend this.

Repro code

I reduced the repro to this:

obj ()
|> hash
|> System.Console.WriteLine

Works with Fable 2 (REPL), fails with Fable 3 (REPL)and in Node. Node gives a little bit more info than the browser:

G:\experiments\Fable3Playground\dist\main.js:59
                const hashes = Object.values(self).map((v) => structuralHash(v));
                                             ^

ReferenceError: self is not defined
    at structuralHash (G:\experiments\Fable3Playground\dist\main.js:59:46)
    at G:\experiments\Fable3Playground\dist\main.js:72:13
    at Object.<anonymous> (G:\experiments\Fable3Playground\dist\main.js:74:3)

Expected and actual results

This affects functions such as List.distinct, because they use structuralHash internally. Not sure if this is expected, though.

Changing self to x in the following line fixes this:

https://github.com/fable-compiler/Fable/blob/6258ded078b5421925dc158e4caced6a9c8d74bd/src/fable-library/Util.ts#L274

Related information

  • Fable version: 3.0.0-nagareyama-rc-007
  • Operating system: N/A

Most helpful comment

When Typescript cannot catch a mistyping

TypeScript is just plain old JavaScript in disguise, so I'm not surprised 馃槃

Fable 3 makes it really easy to set up small repro cases without having to set up a bunch of stuff or to rely on a template 馃憦馃徎

All 2 comments

When Typescript cannot catch a mistyping 馃う I'd like that all bug reports came with a fix, thanks a lot @inosik!

When Typescript cannot catch a mistyping

TypeScript is just plain old JavaScript in disguise, so I'm not surprised 馃槃

Fable 3 makes it really easy to set up small repro cases without having to set up a bunch of stuff or to rely on a template 馃憦馃徎

Was this page helpful?
0 / 5 - 0 ratings