aboutsummaryrefslogtreecommitdiff
path: root/haddock-api
diff options
context:
space:
mode:
authorSimon Jakobi <simon.jakobi@gmail.com>2018-05-08 19:48:11 +0200
committerSimon Jakobi <simon.jakobi@gmail.com>2018-06-13 23:39:30 +0200
commit8bc1c577a1a54f7326c408b52753ec3ed97fa7bc (patch)
tree0043054fb73df118779242a379b93234c47965ff /haddock-api
parent276c352b5dd3dd52b333e0d04ea71f7686ecd7b9 (diff)
Renamer: Warn about out of scope identifiers. (#819)
Diffstat (limited to 'haddock-api')
-rw-r--r--haddock-api/src/Haddock/Interface/LexParseRn.hs17
1 files changed, 11 insertions, 6 deletions
diff --git a/haddock-api/src/Haddock/Interface/LexParseRn.hs b/haddock-api/src/Haddock/Interface/LexParseRn.hs
index c598cb75..c91b89d7 100644
--- a/haddock-api/src/Haddock/Interface/LexParseRn.hs
+++ b/haddock-api/src/Haddock/Interface/LexParseRn.hs
@@ -103,7 +103,9 @@ rename dflags gre = rn
-- We found no names in the env so we start guessing.
[] ->
case choices of
+ -- This shouldn't happen as 'dataTcOccs' always returns at least its input.
[] -> pure (DocMonospaced (DocString (showPpr dflags x)))
+
-- There was nothing in the environment so we need to
-- pick some default from what's available to us. We
-- diverge here from the old way where we would default
@@ -112,7 +114,7 @@ rename dflags gre = rn
-- type constructor names (such as in #253). So now we
-- only get type constructor links if they are actually
-- in scope.
- a:_ -> pure (outOfScope dflags a)
+ a:_ -> outOfScope dflags a
-- There is only one name in the environment that matches so
-- use it.
@@ -153,12 +155,15 @@ rename dflags gre = rn
-- users shouldn't rely on this doing the right thing. See tickets
-- #253 and #375 on the confusion this causes depending on which
-- default we pick in 'rename'.
-outOfScope :: DynFlags -> RdrName -> Doc a
+outOfScope :: DynFlags -> RdrName -> ErrMsgM (Doc a)
outOfScope dflags x =
case x of
- Unqual occ -> monospaced occ
- Qual mdl occ -> DocIdentifierUnchecked (mdl, occ)
- Orig _ occ -> monospaced occ
- Exact name -> monospaced name -- Shouldn't happen since x is out of scope
+ Unqual occ -> warnAndMonospace occ
+ Qual mdl occ -> pure (DocIdentifierUnchecked (mdl, occ))
+ Orig _ occ -> warnAndMonospace occ
+ Exact name -> warnAndMonospace name -- Shouldn't happen since x is out of scope
where
+ warnAndMonospace a = do
+ tell ["Warning: '" ++ showPpr dflags a ++ "' is out of scope."]
+ pure (monospaced a)
monospaced a = DocMonospaced (DocString (showPpr dflags a))