diff options
author | Luke Lau <luke_lau@icloud.com> | 2020-05-28 20:51:32 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-06-10 04:17:22 -0400 |
commit | 32fd37f5e1e6dc6e3b664ae41e0041ed8a19ae21 (patch) | |
tree | 253ef3b37d1db85a67f19cfbc8b3e7263eac3d03 /compiler/GHC/Rename/Unbound.hs | |
parent | 6d49d5be904c0c01788fa7aae1b112d5b4dfaf1c (diff) | |
download | haskell-32fd37f5e1e6dc6e3b664ae41e0041ed8a19ae21.tar.gz |
Fix lookupGlobalOccRn_maybe sometimes reporting an error
In some cases it was possible for lookupGlobalOccRn_maybe to return an
error, when it should be returning a Nothing. If it called
lookupExactOcc_either when there were no matching GlobalRdrElts in the
otherwise case, it would return an error message. This could be caused
when lookupThName_maybe in Template Haskell was looking in different
namespaces (thRdrNameGuesses), guessing different namespaces that the
name wasn't guaranteed to be found in.
However, by addressing this some more accurate errors were being lost in
the conversion to Maybes. So some of the lookup* functions have been
shuffled about so that errors should always be ignored in
lookup*_maybes, and propagated otherwise.
This fixes #18263
Diffstat (limited to 'compiler/GHC/Rename/Unbound.hs')
-rw-r--r-- | compiler/GHC/Rename/Unbound.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/GHC/Rename/Unbound.hs b/compiler/GHC/Rename/Unbound.hs index d37c7d62c0..f97d52aac1 100644 --- a/compiler/GHC/Rename/Unbound.hs +++ b/compiler/GHC/Rename/Unbound.hs @@ -14,6 +14,7 @@ module GHC.Rename.Unbound , unboundName , unboundNameX , notInScopeErr + , exactNameErr ) where @@ -80,8 +81,10 @@ unboundNameX where_look rdr_name extra notInScopeErr :: RdrName -> SDoc notInScopeErr rdr_name - = hang (text "Not in scope:") - 2 (what <+> quotes (ppr rdr_name)) + = case isExact_maybe rdr_name of + Just name -> exactNameErr name + Nothing -> hang (text "Not in scope:") + 2 (what <+> quotes (ppr rdr_name)) where what = pprNonVarNameSpace (occNameSpace (rdrNameOcc rdr_name)) @@ -385,3 +388,10 @@ there are 2 cases, where we hide the last "no module is imported" line: and we have to check the current module in the last added entry of the HomePackageTable. (See test T15611b) -} + +exactNameErr :: Name -> SDoc +exactNameErr name = + hang (text "The exact Name" <+> quotes (ppr name) <+> ptext (sLit "is not in scope")) + 2 (vcat [ text "Probable cause: you used a unique Template Haskell name (NameU), " + , text "perhaps via newName, but did not bind it" + , text "If that's it, then -ddump-splices might be useful" ]) |