[GHC] #9533: Signed/unsigned integer difference between compiled and interpreted code

GHC ghc-devs at haskell.org
Sun Aug 31 15:09:06 UTC 2014


#9533: Signed/unsigned integer difference between compiled and interpreted code
-------------------------------------+-------------------------------------
       Reporter:  MichaelBurge       |                   Owner:
           Type:  bug                |                  Status:  new
       Priority:  normal             |               Milestone:
      Component:  Compiler           |                 Version:  7.8.3
       Keywords:                     |        Operating System:  Windows
   Architecture:  x86_64 (amd64)     |         Type of failure:  Incorrect
     Difficulty:  Unknown            |  result at runtime
     Blocked By:                     |               Test Case:
Related Tickets:                     |                Blocking:
                                     |  Differential Revisions:
-------------------------------------+-------------------------------------
 The following code outputs "A".
 {{{#!hs
 import Data.Word

 x :: Word
 x = 10

 y :: Word
 y = 11

 test = case x - y of
          -1 -> "A"
          _  -> "B"
 main = putStrLn $ show test
 }}}

 However, adding a new case that isn't matched causes the output to change:
 {{{#!hs
 import Data.Word

 x :: Word
 x = 10

 y :: Word
 y = 11

 test = case x - y of
          5 -> "C"
          -1 -> "A"
          _  -> "B"
 main = putStrLn $ show test
 }}}

 With the extra '5 -> "C"' line in the case, the output is "B".

 It gets weirder - interpreted code actually continues to match the -1
 case. With the second example in a file 'T.hs', here is a GHCi session:
 {{{
 Prelude Main> :l *T.hs
 [1 of 1] Compiling Main             ( T.hs, interpreted )
 Ok, modules loaded: Main.
 *Main> main
 "A"
 *Main> :l T.hs
 Ok, modules loaded: Main.
 Prelude Main> main
 "B"
 Prelude Main>
 }}}

 These examples suggest to me at least 3 improvements:
 * Issue a warning when a negative number is used in a case statement in
 unsigned context
 * Interpreted code should give the same result as compiled code
 * Adding a case that isn't matched shouldn't change which other patterns
 get matched

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


More information about the ghc-tickets mailing list