Skip to content

-XStrict doesn't prevent warnings from -Wunbanged-strict-patterns

I'm using:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.3

I was under the impression that -XStrict automatically included outermost bang patterns, but either that isn't always the case or -Wunbanged-strict-patterns doesn't know that -XStrict did its job correctly:

{-# OPTIONS_GHC -Wunbanged-strict-patterns #-}
{-# LANGUAGE BangPatterns, MagicHash, Strict, UnboxedTuples #-}

module Example where

import GHC.Exts  (Int(I#), quotRemInt#)

lastDigit :: Int -> Int
lastDigit (I# x) = let (# q, r #) = quotRemInt# x 10#
                   in  I# r

compiles with a warning:

[1 of 1] Compiling Example          ( Example.hs, Example.o )

Example.hs:9:24: warning: [-Wunbanged-strict-patterns]
    Pattern bindings containing unlifted types should use
    an outermost bang pattern:
      (# q, r #) = quotRemInt# x 10#
  |
9 | lastDigit (I# x) = let (# q, r #) = quotRemInt# x 10#
  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trac metadata
Trac field Value
Version 8.4.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information