-
--- lookupSigOccRn is used for type signatures and pragmas
--- Is this valid?
--- module A
--- import M( f )
--- f :: Int -> Int
--- f x = x
--- It's clear that the 'f' in the signature must refer to A.f
--- The Haskell98 report does not stipulate this, but it will!
--- So we must treat the 'f' in the signature in the same way
--- as the binding occurrence of 'f', using lookupBndrRn
---
--- However, consider this case:
--- import M( f )
--- f :: Int -> Int
--- g x = x
--- We don't want to say 'f' is out of scope; instead, we want to
--- return the imported 'f', so that later on the reanamer will
--- correctly report "misplaced type sig".
-
-lookupSigOccRn :: Maybe NameSet -> Sig RdrName -> Located RdrName -> RnM (Located Name)
-lookupSigOccRn mb_names sig (L loc v)
- = do { mb_n <- lookupBndrRn_maybe v
- ; case mb_n of {
- Just n -> case mb_names of {
- Nothing -> return (L loc n) ;
- Just ns | n `elemNameSet` ns -> return (L loc n)
- | otherwise -> bale_out_with local_msg } ;
-
- Nothing -> do
- { mb_n <- lookupGreRn_maybe v
- ; case mb_n of
- Just _ -> bale_out_with import_msg
- Nothing -> bale_out_with empty
- } }}
- where
- bale_out_with msg
- = do { addErr (sep [ ptext (sLit "The") <+> hsSigDoc sig
- <+> ptext (sLit "for") <+> quotes (ppr v)
- , nest 2 $ ptext (sLit "lacks an accompanying binding")]
- $$ nest 2 msg)
- ; return (L loc (mkUnboundName v)) }
-
- local_msg = parens $ ptext (sLit "The") <+> hsSigDoc sig <+> ptext (sLit "must be given where")
- <+> quotes (ppr v) <+> ptext (sLit "is declared")
-
- import_msg = parens $ ptext (sLit "You cannot give a") <+> hsSigDoc sig
- <+> ptext (sLit "an imported value")