-lookupRecordBndr :: Maybe (Located Name) -> Located RdrName -> RnM (Located Name)
--- Used for record construction and pattern matching
--- When the -XDisambiguateRecordFields flag is on, take account of the
--- constructor name to disambiguate which field to use; it's just the
--- same as for instance decls
---
--- NB: Consider this:
--- module Foo where { data R = R { fld :: Int } }
--- module Odd where { import Foo; fld x = x { fld = 3 } }
--- Arguably this should work, because the reference to 'fld' is
--- unambiguous because there is only one field id 'fld' in scope.
--- But currently it's rejected.
-lookupRecordBndr Nothing rdr_name
- = lookupLocatedGlobalOccRn rdr_name
-lookupRecordBndr (Just (L _ data_con)) rdr_name
- = do { flag_on <- doptM Opt_DisambiguateRecordFields
- ; if not flag_on
- then lookupLocatedGlobalOccRn rdr_name
- else do {
- fields <- lookupConstructorFields data_con
- ; let is_field gre = gre_name gre `elem` fields
- ; lookup_located_sub_bndr is_field doc rdr_name
- }}
- where
- doc = ptext (sLit "field of constructor") <+> quotes (ppr data_con)
-
-