Skip to content

Disabling core optimizations ignores code that would otherwise warn.

Given the below code snippet,

module Main where

main :: IO ()
main = putStrLn "hey"

data StopLight
  = Red
  | Green
  | Yellow
  deriving (Show, Eq)

data Intersection
  = Intersection
  { light :: {-# UNPACK #-} !StopLight
  } deriving (Show, Eq)

The above code will warn with optimizations enabled (ghc -Wall -O2 Main.hs), message below:

Main.hs:13:5: warning:
    • Ignoring unusable UNPACK pragma
        on the first argument of ‘Intersection’
    • In the definition of data constructor ‘Intersection’
      In the data type declaration for ‘Intersection’
   |
13 |   = Intersection

Without optimizations, no warnings are emitted ghc -Wall -O0 Main.hs.

The desired behavior should be a warning emitted in both cases.

Edited by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information