Commit 009e86f5 authored by Joachim Breitner's avatar Joachim Breitner

Suggest Int when user writes int

and the other way around. This fixes #9177.
parent f9def077
......@@ -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
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment