Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,323
    • Issues 4,323
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 377
    • Merge Requests 377
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #9533

Closed
Open
Opened 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
Assignee
Assign to
8.2.1
Milestone
8.2.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#9533