binary icon indicating copy to clipboard operation
binary copied to clipboard

Generic instance of Binary is broken for types with 256 constructors

Open BBBSnowball opened this issue 5 years ago • 0 comments
trafficstars

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.

BBBSnowball avatar May 26 '20 23:05 BBBSnowball