Skip to content

hsc2hs should add explicit type annotations to peeks and pokes

Can you guess what is wrong with this piece of code?

  c_len   <- #{peek ZNotice_t, z_message_len}     c_note
  c_msg   <- #{peek ZNotice_t, z_message}         c_note
  message <- B.packCStringLen (c_msg, c_len)

The problem here is that c_len needs to be interpreted as type CInt, but packCStringLen takes an ``Int\ as an argument. Inference happens, and it so happens that in circumstances when CInt does not equal Int, this will read out too much or little, with no type errors!

Probably the right thing to do here is to add an explicit type annotation to the resulting Haskell code, so peekByteOff is forced to read out the correct amount of information. This will break any code that was reading directly to Haskell level types, but one could make the reasonable argument that these programs were supposed to be ill-typed anyway.

It's not obvious to me if hsc2hs actually has access to this information. So that might make this difficult to implement.

Trac metadata
Trac field Value
Version 7.0.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component hsc2hs
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information