@@ -24,6 +24,7 @@ import Language.PureScript.Crash
2424import Language.PureScript.Kinds
2525import Language.PureScript.Names
2626import Language.PureScript.Pretty
27+import Language.PureScript.Traversals
2728import Language.PureScript.Types
2829import qualified Language.PureScript.Bundle as Bundle
2930import qualified Language.PureScript.Constants as C
@@ -112,7 +113,7 @@ data SimpleErrorMessage
112113 | ShadowedTypeVar String
113114 | UnusedTypeVar String
114115 | WildcardInferredType Type
115− | HoleInferredType String Type
116+ | HoleInferredType String Type [(Ident, Type)]
116117 | MissingTypeDeclaration Ident Type
117118 | OverlappingPattern [[Binder]] Bool
118119 | IncompleteExhaustivityCheck
@@ -395,7 +396,7 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
395396 gSimple (ExpectedType ty k) = ExpectedType <$> f ty <*> pure k
396397 gSimple (OrphanInstance nm cl ts) = OrphanInstance nm cl <$> traverse f ts
397398 gSimple (WildcardInferredType ty) = WildcardInferredType <$> f ty
398− gSimple (HoleInferredType name ty) = HoleInferredType name <$> f ty
399+ gSimple (HoleInferredType name ty env) = HoleInferredType name <$> f ty <*> traverse (sndM f) env
399400 gSimple (MissingTypeDeclaration nm ty) = MissingTypeDeclaration nm <$> f ty
400401 gSimple (CannotGeneralizeRecursiveFunction nm ty) = CannotGeneralizeRecursiveFunction nm <$> f ty
401402
@@ -494,7 +495,7 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
494495 : foldMap (return . line . (" bound at " ++) . displayStartEndPos) ss
495496
496497 unknownInfo :: Int -> Box.Box
497− unknownInfo u = line $ "_" ++ show u ++ " is an unknown type"
498+ unknownInfo u = line $ "t" ++ show u ++ " is an unknown type"
498499
499500 renderSimpleErrorMessage :: SimpleErrorMessage -> Box.Box
500501 renderSimpleErrorMessage (CannotGetFileInfo path) =
@@ -817,10 +818,20 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
817818 paras [ line "Wildcard type definition has the inferred type "
818819 , indent $ typeAsBox ty
819820 ]
820− renderSimpleErrorMessage (HoleInferredType name ty) =
821− paras [ line $ "Hole '" ++ name ++ "' has the inferred type "
822− , indent $ typeAsBox ty
823− ]
821+ renderSimpleErrorMessage (HoleInferredType name ty env) =
822+ paras $ [ line $ "Hole '" ++ name ++ "' has the inferred type "
823+ , indent $ typeAsBox ty
824+ ] ++ if null env then [] else envInfo
825+ where
826+ envInfo :: [Box.Box]
827+ envInfo = [ line "in the following context:"
828+ , indent $ paras
829+ [ Box.hcat Box.left [ Box.text (showIdent ident <> " :: ")
830+ , typeAsBox ty'
831+ ]
832+ | (ident, ty') <- take 5 env
833+ ]
834+ ]
824835 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
825836 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
826837 , line "It is good practice to provide type declarations as a form of documentation."