#5659: hsc2hs should add explicit type annotations to peeks and pokes
---------------------------------+------------------------------------------
    Reporter:  ezyang            |       Owner:                             
        Type:  bug               |      Status:  new                        
    Priority:  normal            |   Component:  hsc2hs                     
     Version:  7.0.2             |    Keywords:                             
    Testcase:                    |   Blockedby:                             
          Os:  Unknown/Multiple  |    Blocking:                             
Architecture:  Unknown/Multiple  |     Failure:  GHC accepts invalid program
---------------------------------+------------------------------------------
 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.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5659>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to