summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2014-06-06 11:47:28 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2014-06-06 13:16:48 +0200
commit009e86f5dd2bc2657be093c76ba679b7866b651a (patch)
tree463cc37c54972e74090f148a8d8ab04fec75d16f
parentf9def077e0938513b62863f3018ad07017e79238 (diff)
downloadhaskell-009e86f5dd2bc2657be093c76ba679b7866b651a.tar.gz
Suggest Int when user writes int
and the other way around. This fixes #9177.
-rw-r--r--compiler/basicTypes/OccName.lhs25
-rw-r--r--compiler/rename/RnEnv.lhs1
2 files changed, 26 insertions, 0 deletions
diff --git a/compiler/basicTypes/OccName.lhs b/compiler/basicTypes/OccName.lhs
index 487318bb09..b1fd831082 100644
--- a/compiler/basicTypes/OccName.lhs
+++ b/compiler/basicTypes/OccName.lhs
@@ -83,6 +83,8 @@ module OccName (
isTcClsNameSpace, isTvNameSpace, isDataConNameSpace, isVarNameSpace, isValNameSpace,
+ toRelatedNameSpace,
+
-- * The 'OccEnv' type
OccEnv, emptyOccEnv, unitOccEnv, extendOccEnv, mapOccEnv,
lookupOccEnv, mkOccEnv, mkOccEnv_C, extendOccEnvList, elemOccEnv,
@@ -370,6 +372,29 @@ demoteOccName (OccName space name) = do
space' <- demoteNameSpace space
return $ OccName space' name
+-- What would this name be if used in the related name space
+-- (variables <-> data construtors, type variables <-> type constructors)
+toRelatedNameSpace :: OccName -> Maybe OccName
+toRelatedNameSpace (OccName space name) = OccName (otherNameSpace space) `fmap` name'
+ where
+ name' | name == fsLit "[]" = Nothing -- Some special cases first
+ | name == fsLit "->" = Nothing
+ | hd == '(' = Nothing
+ | hd == ':' = Just tl
+ | startsVarSym hd = Just (':' `consFS` name)
+ | isUpper hd = Just (toLower hd `consFS` tl)
+ | isLower hd = Just (toUpper hd `consFS` tl)
+ | otherwise = pprTrace "toRelatedNameSpace" (ppr name)
+ Nothing
+ (hd,tl) = (headFS name, tailFS name)
+
+otherNameSpace :: NameSpace -> NameSpace
+otherNameSpace VarName = DataName
+otherNameSpace DataName = VarName
+otherNameSpace TvName = TcClsName
+otherNameSpace TcClsName = TvName
+
+
{- | Other names in the compiler add aditional information to an OccName.
This class provides a consistent way to access the underlying OccName. -}
class HasOccName name where
diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs
index d79fae42f7..d0c51d3fa5 100644
--- a/compiler/rename/RnEnv.lhs
+++ b/compiler/rename/RnEnv.lhs
@@ -1478,6 +1478,7 @@ unknownNameSuggestErr where_look tried_rdr_name
correct_name_space occ = occNameSpace occ == tried_ns
&& isSymOcc occ == tried_is_sym
+ || toRelatedNameSpace occ == Just tried_occ
-- Treat operator and non-operators as non-matching
-- This heuristic avoids things like
-- Not in scope 'f'; perhaps you meant '+' (from Prelude)