Skip to content

Binding incorrectly reported as shadowed when using `NoFieldSelectors`

Summary

When using the NoFieldSelectors language extension, GHC 9.8.1 incorrectly reports that bindings shadow field selectors. I believe that this is a regression from GHC 9.6.4 and before.

Steps to reproduce

Compiling the following module with GHC 9.8.1:

{-# OPTIONS_GHC -Wname-shadowing #-}
{-# LANGUAGE Haskell2010 #-} -- Necessary to avoid `NamedFieldPuns` from `GHC2021`.
{-# LANGUAGE NoFieldSelectors #-}
module M where
data T = C { x :: () }
f x = x

Gives me the following warning:

M.hs:6:3: warning: [GHC-63397] [-Wname-shadowing]
    This binding for ‘x’ shadows the existing binding
      defined at M.hs:5:14
  |
6 | f x = x
  |   ^

Expected behavior

There should not be any warnings when compiling that module. The field selector x does not exist, so using it as a function argument does not shadow anything. Changing line 6 to be f = x gives this error:

M.hs:6:5: error: [GHC-88464]
    Variable not in scope: x
    Suggested fix:
      Notice that ‘x’ is a field selector belonging to the type ‘T’
      that has been suppressed by NoFieldSelectors.
  |
6 | f = x
  |     ^

Environment

  • GHC version used: 9.8.1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information