-ddump-minimal-imports for record fields is not minimal
Summary
When -ddump-minimal-imports is used for a module that uses a record field but not the corresponding type constructor, it generates an import of the form T(x) when it would suffice to import x.
Note [Overloaded field import] in GHC.Rename.Names addresses a special case of this situation, when DuplicateRecordFields is used. I think this is outdated though because it claims "when DuplicateRecordFields is enabled, field selectors are not in scope without their enclosing datatype" which is no longer true in general.
Steps to reproduce
module M where
data T = MkT { x :: Int }
module N where
import M
foo = x
Now ghc -ddump-minimal-imports N.hs will generate N.imports containing import M (T(foo)).
Expected behavior
The N.imports file should contain import M (foo). Using this import is sufficient to compile the module.
Environment
- GHC version used: 9.4.1