diff --git a/compiler/GHC/Tc/Utils/Env.hs b/compiler/GHC/Tc/Utils/Env.hs index abb4289dfcade4477e9e1fdb68d337b741a4b7d6..9e4889a0103a233a417572a7c6ac6b085a22922a 100644 --- a/compiler/GHC/Tc/Utils/Env.hs +++ b/compiler/GHC/Tc/Utils/Env.hs @@ -106,7 +106,7 @@ import GHC.Unit.External import GHC.Utils.Outputable import GHC.Utils.Panic import GHC.Utils.Encoding -import GHC.Utils.Misc ( HasDebugCallStack, fuzzyLookup ) +import GHC.Utils.Misc ( HasDebugCallStack, fuzzyLookup, (<&&>) ) import GHC.Data.FastString import GHC.Data.Bag @@ -1078,7 +1078,12 @@ notFound name | isUnboundName name -> failM -- If the name really isn't in scope -- don't report it again (#11941) | otherwise -> failWithTc (TcRnStageRestriction (StageCheckSplice name)) - _ -> failWithTc $ notInScope lcl_env + _ -> do + names_in_scope <- + map greName + <$> filter (ok_gre <&&> isLocalGRE) + <$> globalRdrEnvElts <$> getGlobalRdrEnv + failWithTc $ notInScope names_in_scope lcl_env -- Take care: printing the whole gbl env can -- cause an infinite loop, in the case where we -- are in the middle of a recursive TyCon/Class group; @@ -1086,14 +1091,22 @@ notFound name -- very unhelpful, because it hides one compiler bug with another } where + occ = rdrNameOcc rdrName + ns = occNameSpace occ + relevant_gres = + RelevantGREs + { includeFieldSelectors = WantBoth + , lookupVariablesForFields = True + , lookupTyConsAsWell = True } + ok_gre = greIsRelevant relevant_gres ns rdrName = getRdrName name - similar_names - = map SimilarName $ fuzzyLookup (unpackFS $ occNameFS $ rdrNameOcc $ rdrName) - $ map (\x -> ((unpackFS $ occNameFS $ nameOccName x), x)) [] - hint = case similar_names of + similar_names names_in_scope + = map SimilarName $ fuzzyLookup (unpackFS $ occNameFS $ occ) + $ map (\x -> ((unpackFS $ occNameFS $ nameOccName x), x)) names_in_scope + hint names_in_scope = case (similar_names names_in_scope) of (nm : nms) -> [SuggestSimilarNames rdrName (nm NE.:| nms)] _ -> [] - notInScope lcl_env = TcRnNotInScope (NotInScopeTc (getLclEnvTypeEnv lcl_env)) rdrName [] hint + notInScope names_in_scope lcl_env = TcRnNotInScope (NotInScopeTc (getLclEnvTypeEnv lcl_env)) rdrName [] (hint names_in_scope) wrongThingErr :: WrongThingSort -> TcTyThing -> Name -> TcM a wrongThingErr expected thing name =