Skip to content

Conversation

BBBSnowball
Copy link

Word8 is used to store the constructor. While this is big enough to store the constructors, the size parameter of getSum and putSum will wrap to zero. We get this error when round-tripping any value of such a type:

Generic:                        
  Generic256: [Failed]                                                                                                                                                                                  
*** Failed! (after 1 test):                                                                         
Exception:                                                                                                                                                                                              
  Data.Binary.Get.runGet at position 1: Unknown encoding for constructor                       
  CallStack (from HasCallStack):                                                                    
    error, called at src/Data/Binary/Get.hs:351:5 in binary-0.8.8.0-EbPVCSphqtF3IWV4ta6LI0:Data.Binary.Get

This PR applies the quick&dirty fix: Use Word16 for such types. This is less space-efficient than using Word8. Alternatively, we could change getSum and putSum to cope with this edge case.

The current implementation uses the output type to store the number
of constructors (e.g. parameter size of putSum). This will fail if
we try to serialize a type with 256 constructors, which can be encoded
in Word8 but its size does not. This is slightly inefficient: We could
use Word8 if getSum and putSum were implemented differently (which would
make them more complicated and probably slower).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant