Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 458
    • Merge requests 458
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9533
Closed
Open
Created Aug 31, 2014 by MichaelBurge@trac-MichaelBurge

Signed/unsigned integer difference between compiled and interpreted code

The following code outputs "A".

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:

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
Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Windows
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking