TemplateHaskell reify fails with fields from DuplicateRecordFields
reify fields from a record defined with
DuplicateRecordFields extension leads to a confusing error message:
Exp.hs:11:1: error: Ambiguous occurrence ‘Exp.foo’ It could refer to either the field ‘foo’, defined at Exp.hs:9:18 or the field ‘foo’, defined at Exp.hs:8:18
Even if the name itself is not present in spliced code.
Steps to reproduce
Complete code snippet is here: https://gist.github.com/maksbotan/146b250ad295c0f5896a2313ce918cd0
- Write TemplateHaskell function of type
Name -> Q [Dec], where
Nameis supposed to refer to a data type.
Names of the
Names to get their types
make :: Name -> Q [Dec] make name = do TyConI (DataD _ _ _ _ [RecC con fields'] _) <- reify name let fields = [ field | (field, _, _) <- fields' ] fieldInfos <- mapM reify fields return 
When the record in question is defined in a file with
DuplicateRecordFields and really has duplicate fields, GHC will
emit a compilation error with confusing message.
reifyed concrete record type, I expect to be able to extras its fields without any ambiguity.
- GHC version used: 8.6.3 (Stack LTS-13.6), 8.6.5 (nix), 8.8.1 (nix)
- Operating System: macOS mojave