Handle singleton records in erlang_to_fate #27
Reference in New Issue
Block a user
Delete Branch "singleton_records"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Sophia doesn't have a concept of singleton tuples, only empty tuples, and tuples of 2 or more elements. It does have a concept of singleton records, however, but instead of implementing these as FATE tuples, it simply leaves the inner value unwrapped in the FATE representation.
I noticed this and implemented it correctly in the Sophia parser and pretty printer, but this is also a case that needs to be implemented on the erlang side! Not hard to do, when turning maps to tuples, if there was only one element produced, we don't wrap it in {tuple, {Inner}}, and going back, we rewrap the FATE term in {tuple, {Inner}} before passing it to our normal record processing logic.
The error message that this case was producing was rather confusing, so I went and fixed that error message too, so instead of "Warning: Unimplemented type "Ping.state", using term as is: 0" it says "Warning: Could not coerce term into record type "Ping.state". Using term as is: 0".
Also while looking at errors in records I noticed that the pathy bit of the error doesn't tell you the name of the field, just what element in the tuple it was, and maybe people want to know the name of the field as well, so I added a little pass to throw that info in too.
Will this also need fixing in Sophia and/or FATE?
No, fortunately, I found this issue on the Sophia side much earlier.
https://git.qpq.swiss/QPQ-AG/hakuzaru/src/branch/master/src/hz_sophia.erl#L1349-L1355