Skip to content

Question: Confusion between `-Wall` and `NamedFieldPuns`

I'm observing an interesting interaction between -Wall and NamedFieldPuns. Perhaps this is perfectly fine but wanted to double check.

I'm using:

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

For this program:

module Test where

data F = F { foo :: Int }

bar :: F -> IO Int
bar f = do foo <- pure (foo f)
           pure foo

I get:

$ ghc -c -Wall Test.hs

Test.hs:6:12: warning: [-Wname-shadowing]
    This binding for ‘foo’ shadows the existing binding
      defined at Test.hs:3:14
  |
6 | bar f = do foo <- pure (foo f)
  |            ^^^

which makes perfect sense to me. However, if I add:

{-# LANGUAGE NamedFieldPuns #-}

at the top, then the warning disappears, even though -Wall option is still present.

Is this the expected behavior? I don't understand how NamedFieldPuns interacts with shadowing here.

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