NoFieldSelectors should prevent importing fields at top level
From #21625 (comment 450472):
It seems that the current implementation of
NoFieldSelectors
is inconsistent between export lists and import lists. Consider the following:{-# LANGUAGE NoFieldSelectors #-} module M where data T = MkT { foo :: Int, bar :: Int } foo = ()
If I instead write an export list
module M (foo)
thefoo
always refers to the value binding, not the field. I have to writeT(foo)
to export the field. (This is documented in the user's guide: https://downloads.haskell.org/ghc/9.4.1/docs/users_guide/exts/field_selectors.html#import-and-export-of-selector-functions). This means the module can choose to export the field or the value binding independently.On the other hand, currently if I write a restricted import list
import M (foo)
thefoo
refers to both the field and the value (so it generates an ambiguity error, or with a variant of !8858 (closed) would import both), whileimport M (bar)
is accepted and imports the field. The user's guide doesn't appear to document what should happen in this case. I think we should be consistent with exports, so thatimport M (foo)
would import only the value binding,import M (T(foo)
would import the field, andimport M (bar)
would be an error.