Shadowing selectors are not warned about / Warn about shadowing top-level names.
An example:
module Shadow (Foo (..)) where
data Foo = Foo { id :: Int, const :: Char }
ghc-9.6.2 -fforce-recomp -Weverything -Wno-missing-safe-haskell-mode -Wno-implicit-prelude -Wno-missing-kind-signatures -Wno-unsafe Shadow.hs
compiles the module without any warnings.
However, id
is obviously shadowing (in fact clashing) with imported name.
I guess it's somewhat consistent with the fact that in "explicit" version
{-# LANGUAGE NoFieldSelectors #-}
module ShadowNoSelectors (Foo (..), ShadowNoSelectors.id) where
data Foo = Foo { id :: Int, const :: Char }
id :: Foo -> Int
id (Foo x _) = x
the ambiguity error will cause only on export. With no export list (i.e. module ShadowNoSelectors where
) there are also no warnings.
So I ask for a warning which warns when a module top-level definition has the same name as some imported binding.
Note: non-top level definitions are warned about:
module NonTop where
foo :: Bool
foo = id True where id = not
NonTop.hs:4:21: warning: [GHC-63397] [-Wname-shadowing]
This binding for ‘id’ shadows the existing binding
imported from ‘Prelude’ at NonTop.hs:1:8-13
(and originally defined in ‘GHC.Base’)
|
4 | foo = id True where id = not
| ^^
which itself is IMHO way less dangerous as the binding is local, and cannot cause problems elsewhere. On the other hand exported top-level ambiguous bindings may cause problems elsewhere (as e.g. defined id
field name in a module without NoFieldSelectors
).