Bug: `union` causes type confusion
maurges opened this issue · 3 comments
Using "purescript": "^0.13.6" and package set psc-0.13.6-20200423
Here's my foot gun:
main :: Effect Unit
main = do
Console.log "1"
let x = union {y: 5} {y: "5"}
Console.log "2"
let s = show x
Console.log "3"
Console.log s
Causes TypeError: s.replace is not a function after logging 2.
Changing to let x = union {y: "5"} {y: 5} gets rid of error and produces expected representation: { y: "5", y: 5 }
Well, "expected" is a bad word, since I was expecting it to fail in all cases with duplicated field names with different types. It also does fail with something like union {y: {y: "y"}} {y: "y"} and produces garbage with union {y: {y: "y"}} {y: 5}
I don't think this is a bug in union per se. This bug happens because the Show implementation for records uses unsafeGet indiscriminately from a RowList, and does not consider whether there are duplicates.
That seems accurate to me. Shall we move this to prelude then?