#94 WxcDefs.hs: Literal 2147483648 is out of the Int range

confirmed
closed-fixed
nobody
None
5
2014-10-25
2014-08-05
No

When wxHaskell is compiled with GHC 7.8.3, the following warning is given:

[10 of 23] Compiling Graphics.UI.WXCore.WxcDefs ( src\haskell\Graphics\UI\WXCore\WxcDefs.hs, dist\build\Graphics\UI\WXCore\WxcDefs.o )

src\haskell\Graphics\UI\WXCore\WxcDefs.hs:3437:13: Warning:
    Literal 2147483648 is out of the Int range -2147483648..2147483647

The offending part in the source file:

wxVSCROLL :: Int
wxVSCROLL = 0x80000000

The constant is handled as if it were a negative number, therefore, you cannot add this to other flags, as is done in two sample programs:

>Findstr /s /c:"wxVSCROLL" *.hs *.lhs 
samples\wxcore\ImageViewer.hs:       s <- scrolledWindowCreate f idAny rectNull (wxHSCROLL + wxVSCROLL + wxNO_FULL_REPAINT_ON_RESIZE + wxCLIP_CHILDREN)
samples\wxcore\Paint.hs:       s <- scrolledWindowCreate f idAny rectNull (wxHSCROLL + wxVSCROLL + wxNO_FULL_REPAINT_ON_RESIZE + wxCLIP_CHILDREN)

One solution, is to change the type of the constants to Word32 (from Data.Word) (this is lot of work, as lot of function types have to change), another is to never use + to combine flags, but .|. (from Data.Bits).

Discussion

  • Maybe the impact of the wrong typing is not as big as I thought, see the following GHCi session:

    Prelude Data.Bits Data.Word> ((0x80000000 .|. 0x40000000) :: Int) == ((0x80000000 + 0x40000000) :: Int)
    
    <interactive>:18:3: Warning:
        Literal 2147483648 is out of the Int range -2147483648..2147483647
        If you are trying to write a large negative literal, use NegativeLiterals
    
    <interactive>:18:43: Warning:
        Literal 2147483648 is out of the Int range -2147483648..2147483647
        If you are trying to write a large negative literal, use NegativeLiterals
    True
    
     
    • status: open --> closed-fixed
     
  • The warning is suppressed by casting (see patch "Casting to remove a compiler warning about Int being too big and some minor improvements")