@@ -10,7 +10,7 @@ import Prelude.Compat
10import Data.Ord (comparing)
10import Data.Ord (comparing)
11import Data.Char (isSpace)
11import Data.Char (isSpace)
12import Data.Either (lefts, rights)
12import Data.Either (lefts, rights)
13−import Data.List (intercalate, transpose, nub, nubBy, sortBy)
13+import Data.List (intercalate, transpose, nub, nubBy, sortBy, partition)
14import Data.Foldable (fold)
14import Data.Foldable (fold)
15import Data.Maybe (maybeToList)
15import Data.Maybe (maybeToList)
@@ -128,6 +128,7 @@ data SimpleErrorMessage
128 | ShadowedTypeVar String
128 | ShadowedTypeVar String
129 | UnusedTypeVar String
129 | UnusedTypeVar String
130 | WildcardInferredType Type
130 | WildcardInferredType Type
131+ | HoleInferredType String Type
131 | MissingTypeDeclaration Ident Type
132 | MissingTypeDeclaration Ident Type
132 | NotExhaustivePattern [[Binder]] Bool
133 | NotExhaustivePattern [[Binder]] Bool
133 | OverlappingPattern [[Binder]] Bool
134 | OverlappingPattern [[Binder]] Bool
@@ -316,6 +317,7 @@ errorCode em = case unwrapErrorMessage em of
316 ShadowedTypeVar{} -> "ShadowedTypeVar"
317 ShadowedTypeVar{} -> "ShadowedTypeVar"
317 UnusedTypeVar{} -> "UnusedTypeVar"
318 UnusedTypeVar{} -> "UnusedTypeVar"
318 WildcardInferredType{} -> "WildcardInferredType"
319 WildcardInferredType{} -> "WildcardInferredType"
320+ HoleInferredType{} -> "HoleInferredType"
319 MissingTypeDeclaration{} -> "MissingTypeDeclaration"
321 MissingTypeDeclaration{} -> "MissingTypeDeclaration"
320 NotExhaustivePattern{} -> "NotExhaustivePattern"
322 NotExhaustivePattern{} -> "NotExhaustivePattern"
321 OverlappingPattern{} -> "OverlappingPattern"
323 OverlappingPattern{} -> "OverlappingPattern"
@@ -435,6 +437,7 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
435 gSimple (ExpectedType ty k) = ExpectedType <$> f ty <*> pure k
437 gSimple (ExpectedType ty k) = ExpectedType <$> f ty <*> pure k
436 gSimple (OrphanInstance nm cl ts) = OrphanInstance nm cl <$> traverse f ts
438 gSimple (OrphanInstance nm cl ts) = OrphanInstance nm cl <$> traverse f ts
437 gSimple (WildcardInferredType ty) = WildcardInferredType <$> f ty
439 gSimple (WildcardInferredType ty) = WildcardInferredType <$> f ty
440+ gSimple (HoleInferredType name ty) = HoleInferredType name <$> f ty
438 gSimple (MissingTypeDeclaration nm ty) = MissingTypeDeclaration nm <$> f ty
441 gSimple (MissingTypeDeclaration nm ty) = MissingTypeDeclaration nm <$> f ty
439 gSimple (CannotGeneralizeRecursiveFunction nm ty) = CannotGeneralizeRecursiveFunction nm <$> f ty
442 gSimple (CannotGeneralizeRecursiveFunction nm ty) = CannotGeneralizeRecursiveFunction nm <$> f ty
@@ -872,6 +875,10 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
872 paras [ line "Wildcard type definition has the inferred type "
875 paras [ line "Wildcard type definition has the inferred type "
873 , indent $ typeAsBox ty
876 , indent $ typeAsBox ty
878+ renderSimpleErrorMessage (HoleInferredType name ty) =
879+ paras [ line $ "Hole '" ++ name ++ "' has the inferred type "
880+ , indent $ typeAsBox ty
875 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
882 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
876 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
883 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
877 , line "It is good practice to provide type declarations as a form of documentation."
884 , line "It is good practice to provide type declarations as a form of documentation."
@@ -1362,6 +1369,22 @@ warnAndRethrowWithPosition pos = rethrowWithPosition pos . warnWithPosition pos
1362withPosition :: SourceSpan -> ErrorMessage -> ErrorMessage
1369withPosition :: SourceSpan -> ErrorMessage -> ErrorMessage
1363withPosition pos (ErrorMessage hints se) = ErrorMessage (PositionedError pos : hints) se
1370withPosition pos (ErrorMessage hints se) = ErrorMessage (PositionedError pos : hints) se
1373+-- Runs a computation listening for warnings and then escalating any warnings
1374+-- that match the predicate to error status.
1377+ :: (MonadWriter MultipleErrors m, MonadError MultipleErrors m)
1378+ => (ErrorMessage -> Bool)
1381+escalateWarningWhen isError ma = do
1382+ (a, w) <- censor (const mempty) $ listen ma
1383+ let (errors, warnings) = partition isError (runMultipleErrors w)
1384+ tell $ MultipleErrors warnings
1385+ unless (null errors) $ throwError $ MultipleErrors errors
1366-- Collect errors in in parallel
1389-- Collect errors in in parallel