@@ -10,7 +10,7 @@ import Prelude.Compat
1010import Data.Ord (comparing)
1111import Data.Char (isSpace)
1212import Data.Either (lefts, rights)
13−import Data.List (intercalate, transpose, nub, nubBy, sortBy)
13+import Data.List (intercalate, transpose, nub, nubBy, sortBy, partition)
1414import Data.Foldable (fold)
1515import Data.Maybe (maybeToList)
1616
@@ -128,6 +128,7 @@ data SimpleErrorMessage
128128 | ShadowedTypeVar String
129129 | UnusedTypeVar String
130130 | WildcardInferredType Type
131+ | HoleInferredType String Type
131132 | MissingTypeDeclaration Ident Type
132133 | NotExhaustivePattern [[Binder]] Bool
133134 | OverlappingPattern [[Binder]] Bool
@@ -316,6 +317,7 @@ errorCode em = case unwrapErrorMessage em of
316317 ShadowedTypeVar{} -> "ShadowedTypeVar"
317318 UnusedTypeVar{} -> "UnusedTypeVar"
318319 WildcardInferredType{} -> "WildcardInferredType"
320+ HoleInferredType{} -> "HoleInferredType"
319321 MissingTypeDeclaration{} -> "MissingTypeDeclaration"
320322 NotExhaustivePattern{} -> "NotExhaustivePattern"
321323 OverlappingPattern{} -> "OverlappingPattern"
@@ -435,6 +437,7 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
435437 gSimple (ExpectedType ty k) = ExpectedType <$> f ty <*> pure k
436438 gSimple (OrphanInstance nm cl ts) = OrphanInstance nm cl <$> traverse f ts
437439 gSimple (WildcardInferredType ty) = WildcardInferredType <$> f ty
440+ gSimple (HoleInferredType name ty) = HoleInferredType name <$> f ty
438441 gSimple (MissingTypeDeclaration nm ty) = MissingTypeDeclaration nm <$> f ty
439442 gSimple (CannotGeneralizeRecursiveFunction nm ty) = CannotGeneralizeRecursiveFunction nm <$> f ty
440443
@@ -872,6 +875,10 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
872875 paras [ line "Wildcard type definition has the inferred type "
873876 , indent $ typeAsBox ty
874877 ]
878+ renderSimpleErrorMessage (HoleInferredType name ty) =
879+ paras [ line $ "Hole '" ++ name ++ "' has the inferred type "
880+ , indent $ typeAsBox ty
881+ ]
875882 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
876883 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
877884 , line "It is good practice to provide type declarations as a form of documentation."
@@ -1362,6 +1369,22 @@ warnAndRethrowWithPosition pos = rethrowWithPosition pos . warnWithPosition pos
13621369withPosition :: SourceSpan -> ErrorMessage -> ErrorMessage
13631370withPosition pos (ErrorMessage hints se) = ErrorMessage (PositionedError pos : hints) se
13641371
1372+-- |
1373+-- Runs a computation listening for warnings and then escalating any warnings
1374+-- that match the predicate to error status.
1375+--
1376+escalateWarningWhen
1377+ :: (MonadWriter MultipleErrors m, MonadError MultipleErrors m)
1378+ => (ErrorMessage -> Bool)
1379+ -> m a
1380+ -> m a
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
1386+ return a
1387+
13651388-- |
13661389-- Collect errors in in parallel
13671390--