@@ -20,10 +20,11 @@
20module Language.PureScript.Errors where
20module Language.PureScript.Errors where
22import Data.Either (lefts, rights)
22import Data.Either (lefts, rights)
23−import Data.List (intercalate, transpose, nub)
23+import Data.List (intercalate, transpose, nub, nubBy, partition)
24import Data.Function (on)
24import Data.Function (on)
25#if __GLASGOW_HASKELL__ < 710
25#if __GLASGOW_HASKELL__ < 710
26import Data.Foldable (fold, foldMap)
26import Data.Foldable (fold, foldMap)
27+import Data.Traversable (traverse)
28import Data.Foldable (fold)
29import Data.Foldable (fold)
@@ -53,9 +54,7 @@ import qualified Text.Parsec as P
53import qualified Text.Parsec.Error as PE
54import qualified Text.Parsec.Error as PE
54import Text.Parsec.Error (Message(..))
55import Text.Parsec.Error (Message(..))
57−-- A type of error messages
57+-- | A type of error messages
59data SimpleErrorMessage
58data SimpleErrorMessage
60 = ErrorParsingExterns P.ParseError
59 = ErrorParsingExterns P.ParseError
61 | ErrorParsingFFIModule FilePath
60 | ErrorParsingFFIModule FilePath
@@ -142,45 +141,54 @@ data SimpleErrorMessage
142 | ShadowedTypeVar String
141 | ShadowedTypeVar String
143 | UnusedTypeVar String
142 | UnusedTypeVar String
144 | WildcardInferredType Type
143 | WildcardInferredType Type
144+ | MissingTypeDeclaration Ident
145 | NotExhaustivePattern [[Binder]] Bool
145 | NotExhaustivePattern [[Binder]] Bool
146 | OverlappingPattern [[Binder]] Bool
146 | OverlappingPattern [[Binder]] Bool
147 | IncompleteExhaustivityCheck
147 | IncompleteExhaustivityCheck
148 | ClassOperator ProperName Ident
148 | ClassOperator ProperName Ident
149 | MisleadingEmptyTypeImport ModuleName ProperName
149 | MisleadingEmptyTypeImport ModuleName ProperName
150 | ImportHidingModule ModuleName
150 | ImportHidingModule ModuleName
151− deriving (Show)
151+ deriving Show
153−-- |
153+-- | Error message hints, providing more detailed information about failure.
154−-- Wrapper of simpler errors
154+data ErrorMessageHint
157− = NotYetDefined [Ident] ErrorMessage
155+ = NotYetDefined [Ident]
158− | ErrorUnifyingTypes Type Type ErrorMessage
156+ | ErrorUnifyingTypes Type Type
159− | ErrorInExpression Expr ErrorMessage
157+ | ErrorInExpression Expr
160− | ErrorInModule ModuleName ErrorMessage
158+ | ErrorInModule ModuleName
161− | ErrorInInstance (Qualified ProperName) [Type] ErrorMessage
159+ | ErrorInInstance (Qualified ProperName) [Type]
162− | ErrorInSubsumption Type Type ErrorMessage
160+ | ErrorInSubsumption Type Type
163− | ErrorCheckingType Expr Type ErrorMessage
161+ | ErrorCheckingType Expr Type
164− | ErrorCheckingKind Type ErrorMessage
162+ | ErrorCheckingKind Type
165− | ErrorInferringType Expr ErrorMessage
163+ | ErrorInferringType Expr
166− | ErrorInApplication Expr Type Expr ErrorMessage
164+ | ErrorInApplication Expr Type Expr
167− | ErrorInDataConstructor ProperName ErrorMessage
165+ | ErrorInDataConstructor ProperName
168− | ErrorInTypeConstructor ProperName ErrorMessage
166+ | ErrorInTypeConstructor ProperName
169− | ErrorInBindingGroup [Ident] ErrorMessage
167+ | ErrorInBindingGroup [Ident]
170− | ErrorInDataBindingGroup ErrorMessage
168+ | ErrorInDataBindingGroup
171− | ErrorInTypeSynonym ProperName ErrorMessage
169+ | ErrorInTypeSynonym ProperName
172− | ErrorInValueDeclaration Ident ErrorMessage
170+ | ErrorInValueDeclaration Ident
173− | ErrorInTypeDeclaration Ident ErrorMessage
171+ | ErrorInTypeDeclaration Ident
174− | ErrorInForeignImport Ident ErrorMessage
172+ | ErrorInForeignImport Ident
175− | PositionedError SourceSpan ErrorMessage
173+ | PositionedError SourceSpan
176− | SimpleErrorWrapper SimpleErrorMessage
174+ deriving Show
176+-- | Categories of hints
185+data ErrorMessage = ErrorMessage [ErrorMessageHint] SimpleErrorMessage deriving (Show)
179instance UnificationError Type ErrorMessage where
187instance UnificationError Type ErrorMessage where
180− occursCheckFailed t = SimpleErrorWrapper $ InfiniteType t
188+ occursCheckFailed t = ErrorMessage [] $ InfiniteType t
182instance UnificationError Kind ErrorMessage where
190instance UnificationError Kind ErrorMessage where
183− occursCheckFailed k = SimpleErrorWrapper $ InfiniteKind k
191+ occursCheckFailed k = ErrorMessage [] $ InfiniteKind k
186-- Get the error code for a particular error type
194-- Get the error code for a particular error type
@@ -272,6 +280,7 @@ errorCode em = case unwrapErrorMessage em of
272 ShadowedTypeVar{} -> "ShadowedTypeVar"
280 ShadowedTypeVar{} -> "ShadowedTypeVar"
273 UnusedTypeVar{} -> "UnusedTypeVar"
281 UnusedTypeVar{} -> "UnusedTypeVar"
274 WildcardInferredType{} -> "WildcardInferredType"
282 WildcardInferredType{} -> "WildcardInferredType"
283+ MissingTypeDeclaration{} -> "MissingTypeDeclaration"
275 NotExhaustivePattern{} -> "NotExhaustivePattern"
284 NotExhaustivePattern{} -> "NotExhaustivePattern"
276 OverlappingPattern{} -> "OverlappingPattern"
285 OverlappingPattern{} -> "OverlappingPattern"
277 IncompleteExhaustivityCheck{} -> "IncompleteExhaustivityCheck"
286 IncompleteExhaustivityCheck{} -> "IncompleteExhaustivityCheck"
@@ -299,7 +308,7 @@ nonEmpty = not . null . runMultipleErrors
299-- Create an error set from a single simple error message
308-- Create an error set from a single simple error message
301errorMessage :: SimpleErrorMessage -> MultipleErrors
310errorMessage :: SimpleErrorMessage -> MultipleErrors
302−errorMessage err = MultipleErrors [SimpleErrorWrapper err]
311+errorMessage err = MultipleErrors [ErrorMessage [] err]
@@ -308,12 +317,14 @@ errorMessage err = MultipleErrors [SimpleErrorWrapper err]
308singleError :: ErrorMessage -> MultipleErrors
317singleError :: ErrorMessage -> MultipleErrors
309singleError = MultipleErrors . pure
318singleError = MultipleErrors . pure
312−-- Lift a function on ErrorMessage to a function on MultipleErrors
320+-- | Lift a function on ErrorMessage to a function on MultipleErrors
314onErrorMessages :: (ErrorMessage -> ErrorMessage) -> MultipleErrors -> MultipleErrors
321onErrorMessages :: (ErrorMessage -> ErrorMessage) -> MultipleErrors -> MultipleErrors
315onErrorMessages f = MultipleErrors . map f . runMultipleErrors
322onErrorMessages f = MultipleErrors . map f . runMultipleErrors
324+-- | Add a hint to an error message
325+addHint :: ErrorMessageHint -> MultipleErrors -> MultipleErrors
326+addHint hint = onErrorMessages $ \(ErrorMessage hints se) -> ErrorMessage (hint : hints) se
317-- | The various types of things which might need to be relabelled in errors messages.
328-- | The various types of things which might need to be relabelled in errors messages.
318data LabelType = TypeLabel | SkolemLabel String deriving (Show, Read, Eq, Ord)
329data LabelType = TypeLabel | SkolemLabel String deriving (Show, Read, Eq, Ord)
@@ -327,27 +338,7 @@ data Level = Error | Warning deriving Show
327-- Extract nested error messages from wrapper errors
338-- Extract nested error messages from wrapper errors
329unwrapErrorMessage :: ErrorMessage -> SimpleErrorMessage
340unwrapErrorMessage :: ErrorMessage -> SimpleErrorMessage
330−unwrapErrorMessage em = case em of
341+unwrapErrorMessage (ErrorMessage _ se) = se
331− (ErrorCheckingKind _ err) -> unwrapErrorMessage err
332− (ErrorCheckingType _ _ err) -> unwrapErrorMessage err
333− (ErrorInApplication _ _ _ err) -> unwrapErrorMessage err
334− (ErrorInBindingGroup _ err) -> unwrapErrorMessage err
335− (ErrorInDataBindingGroup err) -> unwrapErrorMessage err
336− (ErrorInDataConstructor _ err) -> unwrapErrorMessage err
337− (ErrorInExpression _ err) -> unwrapErrorMessage err
338− (ErrorInForeignImport _ err) -> unwrapErrorMessage err
339− (ErrorInInstance _ _ err) -> unwrapErrorMessage err
340− (ErrorInModule _ err) -> unwrapErrorMessage err
341− (ErrorInSubsumption _ _ err) -> unwrapErrorMessage err
342− (ErrorInTypeConstructor _ err) -> unwrapErrorMessage err
343− (ErrorInTypeSynonym _ err) -> unwrapErrorMessage err
344− (ErrorInValueDeclaration _ err) -> unwrapErrorMessage err
345− (ErrorInTypeDeclaration _ err) -> unwrapErrorMessage err
346− (ErrorInferringType _ err) -> unwrapErrorMessage err
347− (ErrorUnifyingTypes _ _ err) -> unwrapErrorMessage err
348− (NotYetDefined _ err) -> unwrapErrorMessage err
349− (PositionedError _ err) -> unwrapErrorMessage err
350− (SimpleErrorWrapper sem) -> sem
352replaceUnknowns :: Type -> State UnknownMap Type
343replaceUnknowns :: Type -> State UnknownMap Type
353replaceUnknowns = everywhereOnTypesM replaceTypes
344replaceUnknowns = everywhereOnTypesM replaceTypes
@@ -363,7 +354,7 @@ replaceUnknowns = everywhereOnTypesM replaceTypes
363 replaceTypes other = return other
354 replaceTypes other = return other
365onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
356onTypesInErrorMessageM :: (Applicative m) => (Type -> m Type) -> ErrorMessage -> m ErrorMessage
366−onTypesInErrorMessageM f = g
357+onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse gHint hints <*> gSimple simple
368 gSimple (InfiniteType t) = InfiniteType <$> f t
359 gSimple (InfiniteType t) = InfiniteType <$> f t
369 gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
360 gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
@@ -373,394 +364,394 @@ onTypesInErrorMessageM f = g
373 gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
364 gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
374 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
365 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
375 gSimple other = pure other
366 gSimple other = pure other
376− g (ErrorInSubsumption t1 t2 em) = ErrorInSubsumption <$> f t1 <*> f t2 <*> g em
367+ gHint (ErrorInSubsumption t1 t2) = ErrorInSubsumption <$> f t1 <*> f t2
377− g (ErrorUnifyingTypes t1 t2 e) = ErrorUnifyingTypes <$> f t1 <*> f t2 <*> g e
368+ gHint (ErrorUnifyingTypes t1 t2) = ErrorUnifyingTypes <$> f t1 <*> f t2
378− g (ErrorCheckingType e t em) = ErrorCheckingType e <$> f t <*> g em
369+ gHint (ErrorCheckingType e t) = ErrorCheckingType e <$> f t
379− g (ErrorCheckingKind t em) = ErrorCheckingKind <$> f t <*> g em
370+ gHint (ErrorCheckingKind t) = ErrorCheckingKind <$> f t
380− g (ErrorInApplication e1 t1 e2 em) = ErrorInApplication e1 <$> f t1 <*> pure e2 <*> g em
371+ gHint (ErrorInApplication e1 t1 e2) = ErrorInApplication e1 <$> f t1 <*> pure e2
381− g (NotYetDefined x e) = NotYetDefined x <$> g e
372+ gHint other = pure other
382− g (ErrorInExpression x e) = ErrorInExpression x <$> g e
383− g (ErrorInModule x e) = ErrorInModule x <$> g e
384− g (ErrorInInstance x y e) = ErrorInInstance x y <$> g e
385− g (ErrorInferringType x e) = ErrorInferringType x <$> g e
386− g (ErrorInDataConstructor x e) = ErrorInDataConstructor x <$> g e
387− g (ErrorInTypeConstructor x e) = ErrorInTypeConstructor x <$> g e
388− g (ErrorInBindingGroup x e) = ErrorInBindingGroup x <$> g e
389− g (ErrorInDataBindingGroup e) = ErrorInDataBindingGroup <$> g e
390− g (ErrorInTypeSynonym x e) = ErrorInTypeSynonym x <$> g e
391− g (ErrorInValueDeclaration x e) = ErrorInValueDeclaration x <$> g e
392− g (ErrorInTypeDeclaration x e) = ErrorInTypeDeclaration x <$> g e
393− g (ErrorInForeignImport x e) = ErrorInForeignImport x <$> g e
394− g (PositionedError x e) = PositionedError x <$> g e
395− g (SimpleErrorWrapper sem) = SimpleErrorWrapper <$> gSimple sem
398-- Pretty print a single error, simplifying if necessary
375-- Pretty print a single error, simplifying if necessary
400prettyPrintSingleError :: Bool -> Level -> ErrorMessage -> State UnknownMap Box.Box
377prettyPrintSingleError :: Bool -> Level -> ErrorMessage -> State UnknownMap Box.Box
401−prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
378+prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFirst . reverseHints <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
404 -- Pretty print an ErrorMessage
381 -- Pretty print an ErrorMessage
406 prettyPrintErrorMessage :: ErrorMessage -> Box.Box
382 prettyPrintErrorMessage :: ErrorMessage -> Box.Box
407− prettyPrintErrorMessage em =
383+ prettyPrintErrorMessage (ErrorMessage hints simple) =
385+ map renderHint hints ++
386+ renderSimpleErrorMessage simple :
409− go em:suggestions em ++
387+ suggestions simple ++
410 [line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."]
388 [line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."]
412 wikiUri :: String
390 wikiUri :: String
413 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
391 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
415− go :: ErrorMessage -> Box.Box
393+ renderSimpleErrorMessage :: SimpleErrorMessage -> Box.Box
416− goSimple (CannotGetFileInfo path) =
394+ renderSimpleErrorMessage (CannotGetFileInfo path) =
417 paras [ line "Unable to read file info: "
395 paras [ line "Unable to read file info: "
418 , indent . line $ path
396 , indent . line $ path
420− goSimple (CannotReadFile path) =
398+ renderSimpleErrorMessage (CannotReadFile path) =
421 paras [ line "Unable to read file: "
399 paras [ line "Unable to read file: "
422 , indent . line $ path
400 , indent . line $ path
424− goSimple (CannotWriteFile path) =
402+ renderSimpleErrorMessage (CannotWriteFile path) =
425 paras [ line "Unable to write file: "
403 paras [ line "Unable to write file: "
426 , indent . line $ path
404 , indent . line $ path
428− goSimple (ErrorParsingExterns err) =
406+ renderSimpleErrorMessage (ErrorParsingExterns err) =
429 paras [ lineWithLevel "parsing externs files: "
407 paras [ lineWithLevel "parsing externs files: "
430− , indent . prettyPrintParseError $ err
408+ , prettyPrintParseError err
432− goSimple (ErrorParsingFFIModule path) =
410+ renderSimpleErrorMessage (ErrorParsingFFIModule path) =
433 paras [ line "Unable to parse module from FFI file: "
411 paras [ line "Unable to parse module from FFI file: "
434 , indent . line $ path
412 , indent . line $ path
436− goSimple (ErrorParsingModule err) =
414+ renderSimpleErrorMessage (ErrorParsingModule err) =
437 paras [ line "Unable to parse module: "
415 paras [ line "Unable to parse module: "
438− , indent . prettyPrintParseError $ err
416+ , prettyPrintParseError err
440− goSimple (MissingFFIModule mn) =
418+ renderSimpleErrorMessage (MissingFFIModule mn) =
441 line $ "Missing FFI implementations for module " ++ runModuleName mn
419 line $ "Missing FFI implementations for module " ++ runModuleName mn
442− goSimple (UnnecessaryFFIModule mn path) =
420+ renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
443 paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
421 paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
444 , indent . line $ path
422 , indent . line $ path
446− goSimple (MultipleFFIModules mn paths) =
424+ renderSimpleErrorMessage (MultipleFFIModules mn paths) =
447− paras $ [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": " ]
425+ paras [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
448− ++ map (indent . line) paths
426+ , indent . paras $ map line paths
449− goSimple (InvalidExternsFile path) =
428+ renderSimpleErrorMessage (InvalidExternsFile path) =
450 paras [ line "Externs file is invalid: "
429 paras [ line "Externs file is invalid: "
451 , indent . line $ path
430 , indent . line $ path
453− goSimple InvalidDoBind =
432+ renderSimpleErrorMessage InvalidDoBind =
454 line "Bind statement cannot be the last statement in a do block. The last statement must be an expression."
433 line "Bind statement cannot be the last statement in a do block. The last statement must be an expression."
455− goSimple InvalidDoLet =
434+ renderSimpleErrorMessage InvalidDoLet =
456 line "Let statement cannot be the last statement in a do block. The last statement must be an expression."
435 line "Let statement cannot be the last statement in a do block. The last statement must be an expression."
457− goSimple CannotReorderOperators =
436+ renderSimpleErrorMessage CannotReorderOperators =
458 line "Unable to reorder operators"
437 line "Unable to reorder operators"
459− goSimple UnspecifiedSkolemScope =
438+ renderSimpleErrorMessage UnspecifiedSkolemScope =
460 line "Skolem variable scope is unspecified"
439 line "Skolem variable scope is unspecified"
461− goSimple OverlappingNamesInLet =
440+ renderSimpleErrorMessage OverlappingNamesInLet =
462 line "Overlapping names in let binding."
441 line "Overlapping names in let binding."
463− goSimple (InfiniteType ty) =
442+ renderSimpleErrorMessage (InfiniteType ty) =
464 paras [ line "An infinite type was inferred for an expression: "
443 paras [ line "An infinite type was inferred for an expression: "
465− , indent $ line $ prettyPrintType ty
444+ , indent $ typeAsBox ty
467− goSimple (InfiniteKind ki) =
446+ renderSimpleErrorMessage (InfiniteKind ki) =
468 paras [ line "An infinite kind was inferred for a type: "
447 paras [ line "An infinite kind was inferred for a type: "
469− , indent $ line $ prettyPrintKind ki
448+ , indent $ kindAsBox ki
471− goSimple (MultipleFixities name) =
450+ renderSimpleErrorMessage (MultipleFixities name) =
472 line $ "Multiple fixity declarations for " ++ showIdent name
451 line $ "Multiple fixity declarations for " ++ showIdent name
473− goSimple (OrphanTypeDeclaration nm) =
452+ renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
474 line $ "Orphan type declaration for " ++ showIdent nm
453 line $ "Orphan type declaration for " ++ showIdent nm
475− goSimple (OrphanFixityDeclaration op) =
454+ renderSimpleErrorMessage (OrphanFixityDeclaration op) =
476 line $ "Orphan fixity declaration for " ++ show op
455 line $ "Orphan fixity declaration for " ++ show op
477− goSimple (RedefinedModule name filenames) =
456+ renderSimpleErrorMessage (RedefinedModule name filenames) =
478− paras $ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
457+ paras [ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
479− : map (indent . line . displaySourceSpan) filenames
458+ , indent . paras $ map (line . displaySourceSpan) filenames
480− goSimple (RedefinedIdent name) =
460+ renderSimpleErrorMessage (RedefinedIdent name) =
481 line $ "Name " ++ showIdent name ++ " has been defined multiple times"
461 line $ "Name " ++ showIdent name ++ " has been defined multiple times"
482− goSimple (UnknownModule mn) =
462+ renderSimpleErrorMessage (UnknownModule mn) =
483 line $ "Unknown module " ++ runModuleName mn
463 line $ "Unknown module " ++ runModuleName mn
484− goSimple (UnknownType name) =
464+ renderSimpleErrorMessage (UnknownType name) =
485 line $ "Unknown type " ++ showQualified runProperName name
465 line $ "Unknown type " ++ showQualified runProperName name
486− goSimple (UnknownTypeClass name) =
466+ renderSimpleErrorMessage (UnknownTypeClass name) =
487 line $ "Unknown type class " ++ showQualified runProperName name
467 line $ "Unknown type class " ++ showQualified runProperName name
488− goSimple (UnknownValue name) =
468+ renderSimpleErrorMessage (UnknownValue name) =
489 line $ "Unknown value " ++ showQualified showIdent name
469 line $ "Unknown value " ++ showQualified showIdent name
490− goSimple (UnknownTypeConstructor name) =
470+ renderSimpleErrorMessage (UnknownTypeConstructor name) =
491 line $ "Unknown type constructor " ++ showQualified runProperName name
471 line $ "Unknown type constructor " ++ showQualified runProperName name
492− goSimple (UnknownDataConstructor dc tc) =
472+ renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
493 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
473 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
494− goSimple (UnknownImportType mn name) =
474+ renderSimpleErrorMessage (UnknownImportType mn name) =
495 line $ "Module " ++ runModuleName mn ++ " does not export type " ++ runProperName name
475 line $ "Module " ++ runModuleName mn ++ " does not export type " ++ runProperName name
496− goSimple (UnknownExportType name) =
476+ renderSimpleErrorMessage (UnknownExportType name) =
497 line $ "Cannot export unknown type " ++ runProperName name
477 line $ "Cannot export unknown type " ++ runProperName name
498− goSimple (UnknownImportTypeClass mn name) =
478+ renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
499 line $ "Module " ++ runModuleName mn ++ " does not export type class " ++ runProperName name
479 line $ "Module " ++ runModuleName mn ++ " does not export type class " ++ runProperName name
500− goSimple (UnknownExportTypeClass name) =
480+ renderSimpleErrorMessage (UnknownExportTypeClass name) =
501 line $ "Cannot export unknown type class " ++ runProperName name
481 line $ "Cannot export unknown type class " ++ runProperName name
502− goSimple (UnknownImportValue mn name) =
482+ renderSimpleErrorMessage (UnknownImportValue mn name) =
503 line $ "Module " ++ runModuleName mn ++ " does not export value " ++ showIdent name
483 line $ "Module " ++ runModuleName mn ++ " does not export value " ++ showIdent name
504− goSimple (UnknownExportValue name) =
484+ renderSimpleErrorMessage (UnknownExportValue name) =
505 line $ "Cannot export unknown value " ++ showIdent name
485 line $ "Cannot export unknown value " ++ showIdent name
506− goSimple (UnknownExportModule name) =
486+ renderSimpleErrorMessage (UnknownExportModule name) =
507 line $ "Cannot export unknown module " ++ runModuleName name ++ ", it either does not exist or has not been imported by the current module"
487 line $ "Cannot export unknown module " ++ runModuleName name ++ ", it either does not exist or has not been imported by the current module"
508− goSimple (UnknownImportDataConstructor mn tcon dcon) =
488+ renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
509 line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
489 line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
510− goSimple (UnknownExportDataConstructor tcon dcon) =
490+ renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
511 line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ " as it has not been declared"
491 line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ " as it has not been declared"
512− goSimple (ConflictingImport nm mn) =
492+ renderSimpleErrorMessage (ConflictingImport nm mn) =
513 line $ "Cannot declare " ++ show nm ++ " since another declaration of that name was imported from " ++ runModuleName mn
493 line $ "Cannot declare " ++ show nm ++ " since another declaration of that name was imported from " ++ runModuleName mn
514− goSimple (ConflictingImports nm m1 m2) =
494+ renderSimpleErrorMessage (ConflictingImports nm m1 m2) =
515 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
495 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
516− goSimple (ConflictingTypeDecls nm) =
496+ renderSimpleErrorMessage (ConflictingTypeDecls nm) =
517 line $ "Conflicting type declarations for " ++ runProperName nm
497 line $ "Conflicting type declarations for " ++ runProperName nm
518− goSimple (ConflictingCtorDecls nm) =
498+ renderSimpleErrorMessage (ConflictingCtorDecls nm) =
519 line $ "Conflicting data constructor declarations for " ++ runProperName nm
499 line $ "Conflicting data constructor declarations for " ++ runProperName nm
520− goSimple (TypeConflictsWithClass nm) =
500+ renderSimpleErrorMessage (TypeConflictsWithClass nm) =
521 line $ "Type " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
501 line $ "Type " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
522− goSimple (CtorConflictsWithClass nm) =
502+ renderSimpleErrorMessage (CtorConflictsWithClass nm) =
523 line $ "Data constructor " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
503 line $ "Data constructor " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
524− goSimple (ClassConflictsWithType nm) =
504+ renderSimpleErrorMessage (ClassConflictsWithType nm) =
525 line $ "Type class " ++ runProperName nm ++ " conflicts with type declaration of the same name"
505 line $ "Type class " ++ runProperName nm ++ " conflicts with type declaration of the same name"
526− goSimple (ClassConflictsWithCtor nm) =
506+ renderSimpleErrorMessage (ClassConflictsWithCtor nm) =
527 line $ "Type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name"
507 line $ "Type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name"
528− goSimple (DuplicateClassExport nm) =
508+ renderSimpleErrorMessage (DuplicateClassExport nm) =
529 line $ "Duplicate export declaration for type class " ++ runProperName nm
509 line $ "Duplicate export declaration for type class " ++ runProperName nm
530− goSimple (DuplicateValueExport nm) =
510+ renderSimpleErrorMessage (DuplicateValueExport nm) =
531 line $ "Duplicate export declaration for value " ++ showIdent nm
511 line $ "Duplicate export declaration for value " ++ showIdent nm
532− goSimple (CycleInDeclaration nm) =
512+ renderSimpleErrorMessage (CycleInDeclaration nm) =
533 line $ "Cycle in declaration of " ++ showIdent nm
513 line $ "Cycle in declaration of " ++ showIdent nm
534− goSimple (CycleInModules mns) =
514+ renderSimpleErrorMessage (CycleInModules mns) =
535 line $ "Cycle in module dependencies: " ++ intercalate ", " (map runModuleName mns)
515 line $ "Cycle in module dependencies: " ++ intercalate ", " (map runModuleName mns)
536− goSimple (CycleInTypeSynonym pn) =
516+ renderSimpleErrorMessage (CycleInTypeSynonym pn) =
537 line $ "Cycle in type synonym" ++ foldMap ((" " ++) . runProperName) pn
517 line $ "Cycle in type synonym" ++ foldMap ((" " ++) . runProperName) pn
538− goSimple (NameIsUndefined ident) =
518+ renderSimpleErrorMessage (NameIsUndefined ident) =
539 line $ showIdent ident ++ " is undefined"
519 line $ showIdent ident ++ " is undefined"
540− goSimple (NameNotInScope ident) =
520+ renderSimpleErrorMessage (NameNotInScope ident) =
541 line $ showIdent ident ++ " may not be defined in the current scope"
521 line $ showIdent ident ++ " may not be defined in the current scope"
542− goSimple (UndefinedTypeVariable name) =
522+ renderSimpleErrorMessage (UndefinedTypeVariable name) =
543 line $ "Type variable " ++ runProperName name ++ " is undefined"
523 line $ "Type variable " ++ runProperName name ++ " is undefined"
544− goSimple (PartiallyAppliedSynonym name) =
524+ renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
545 paras [ line $ "Partially applied type synonym " ++ showQualified runProperName name
525 paras [ line $ "Partially applied type synonym " ++ showQualified runProperName name
546 , line "Type synonyms must be applied to all of their type arguments."
526 , line "Type synonyms must be applied to all of their type arguments."
548− goSimple (EscapedSkolem binding) =
528+ renderSimpleErrorMessage (EscapedSkolem binding) =
549 paras $ [ line "A type variable has escaped its scope." ]
529 paras $ [ line "A type variable has escaped its scope." ]
550 <> foldMap (\expr -> [ line "Relevant expression: "
530 <> foldMap (\expr -> [ line "Relevant expression: "
551− , indent $ line $ prettyPrintValue expr
531+ , indent $ prettyPrintValue expr
552 ]) binding
532 ]) binding
553− goSimple (TypesDoNotUnify t1 t2)
533+ renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
554 = paras [ line "Cannot unify type"
534 = paras [ line "Cannot unify type"
555− , indent $ line $ prettyPrintType t1
535+ , indent $ typeAsBox t1
556 , line "with type"
536 , line "with type"
557− , indent $ line $ prettyPrintType t2
537+ , indent $ typeAsBox t2
559− goSimple (KindsDoNotUnify k1 k2) =
539+ renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
560 paras [ line "Cannot unify kind"
540 paras [ line "Cannot unify kind"
561− , indent $ line $ prettyPrintKind k1
541+ , indent $ kindAsBox k1
562 , line "with kind"
542 , line "with kind"
563− , indent $ line $ prettyPrintKind k2
543+ , indent $ kindAsBox k2
565− goSimple (ConstrainedTypeUnified t1 t2) =
545+ renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
566 paras [ line "Cannot unify constrained type"
546 paras [ line "Cannot unify constrained type"
567− , indent $ line $ prettyPrintType t1
547+ , indent $ typeAsBox t1
568 , line "with type"
548 , line "with type"
569− , indent $ line $ prettyPrintType t2
549+ , indent $ typeAsBox t2
571− goSimple (OverlappingInstances nm ts (d : ds)) =
551+ renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
572− paras [ line $ "Overlapping instances found for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
552+ paras [ line "Overlapping instances found for"
553+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
554+ , Box.vcat Box.left (map typeAtomAsBox ts)
556+ , line "The following instances were found:"
573 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
557 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
575− goSimple OverlappingInstances{} = error "OverlappingInstances: empty instance list"
559+ renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
576− goSimple (NoInstanceFound nm ts) =
560+ renderSimpleErrorMessage (NoInstanceFound nm ts) =
577− line $ "No instance found for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts)
561+ paras [ line "No instance found for"
562+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
563+ , Box.vcat Box.left (map typeAtomAsBox ts)
578− goSimple (PossiblyInfiniteInstance nm ts) =
566+ renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
579− line $ "Instance for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ " is possibly infinite."
567+ paras [ line "Instance for"
568+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
569+ , Box.vcat Box.left (map typeAtomAsBox ts)
571+ , line "is possibly infinite."
580− goSimple (CannotDerive nm ts) =
573+ renderSimpleErrorMessage (CannotDerive nm ts) =
581− line $ "Cannot derive " ++ showQualified runProperName nm ++ " instance for " ++ unwords (map prettyPrintTypeAtom ts)
574+ paras [ line "Cannot derive an instance for"
575+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
576+ , Box.vcat Box.left (map typeAtomAsBox ts)
582− goSimple (CannotFindDerivingType nm) =
579+ renderSimpleErrorMessage (CannotFindDerivingType nm) =
583 line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
580 line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
584− goSimple (DuplicateLabel l expr) =
581+ renderSimpleErrorMessage (DuplicateLabel l expr) =
585 paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
582 paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
586 <> foldMap (\expr' -> [ line "Relevant expression: "
583 <> foldMap (\expr' -> [ line "Relevant expression: "
587− , indent $ line $ prettyPrintValue expr'
584+ , indent $ prettyPrintValue expr'
589− goSimple (DuplicateTypeArgument name) =
586+ renderSimpleErrorMessage (DuplicateTypeArgument name) =
590 line $ "Duplicate type argument " ++ show name
587 line $ "Duplicate type argument " ++ show name
591− goSimple (DuplicateValueDeclaration nm) =
588+ renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
592 line $ "Duplicate value declaration for " ++ showIdent nm
589 line $ "Duplicate value declaration for " ++ showIdent nm
593− goSimple (ArgListLengthsDiffer ident) =
590+ renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
594 line $ "Argument list lengths differ in declaration " ++ showIdent ident
591 line $ "Argument list lengths differ in declaration " ++ showIdent ident
595− goSimple (OverlappingArgNames ident) =
592+ renderSimpleErrorMessage (OverlappingArgNames ident) =
596 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
593 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
597− goSimple (MissingClassMember ident) =
594+ renderSimpleErrorMessage (MissingClassMember ident) =
598 line $ "Member " ++ showIdent ident ++ " has not been implemented"
595 line $ "Member " ++ showIdent ident ++ " has not been implemented"
599− goSimple (ExtraneousClassMember ident) =
596+ renderSimpleErrorMessage (ExtraneousClassMember ident) =
600 line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
597 line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
601− goSimple (ExpectedType ty kind) =
598+ renderSimpleErrorMessage (ExpectedType ty kind) =
602 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
599 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
603− , line $ "The error arises from the type " ++ prettyPrintType ty ++ " having the kind " ++ prettyPrintKind kind ++ " instead."
600+ , line "The error arises from the type"
601+ , indent $ typeAsBox ty
602+ , line "having the kind"
603+ , indent $ kindAsBox kind
605− goSimple (IncorrectConstructorArity nm) =
606+ renderSimpleErrorMessage (IncorrectConstructorArity nm) =
606 line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
607 line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
607− goSimple SubsumptionCheckFailed = line "Unable to check type subsumption"
608+ renderSimpleErrorMessage SubsumptionCheckFailed = line "Unable to check type subsumption"
608− goSimple (ExprDoesNotHaveType expr ty) =
609+ renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
609 paras [ line "Expression"
610 paras [ line "Expression"
610− , indent $ line $ prettyPrintValue expr
611+ , indent $ prettyPrintValue expr
611 , line "does not have type"
612 , line "does not have type"
612− , indent $ line $ prettyPrintType ty
613+ , indent $ typeAsBox ty
614− goSimple (PropertyIsMissing prop row) =
615+ renderSimpleErrorMessage (PropertyIsMissing prop row) =
617+ , indent $ prettyPrintRowWith '(' ')' row
615− line $ "Row " ++ prettyPrintRow row ++ " lacks required property " ++ show prop
618+ , line $ "lacks required property " ++ show prop
616− goSimple (CannotApplyFunction fn arg) =
620+ renderSimpleErrorMessage (CannotApplyFunction fn arg) =
617 paras [ line "Cannot apply function of type"
621 paras [ line "Cannot apply function of type"
618− , indent $ line $ prettyPrintType fn
622+ , indent $ typeAsBox fn
619 , line "to argument"
623 , line "to argument"
620− , indent $ line $ prettyPrintValue arg
624+ , indent $ prettyPrintValue arg
622− goSimple TypeSynonymInstance =
626+ renderSimpleErrorMessage TypeSynonymInstance =
623 line "Type synonym instances are disallowed"
627 line "Type synonym instances are disallowed"
624− goSimple (OrphanInstance nm cnm ts) =
628+ renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
625− paras [ line $ "Instance " ++ showIdent nm ++ " for " ++ showQualified runProperName cnm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ " is an orphan instance."
629+ paras [ line $ "Instance " ++ showIdent nm ++ " for "
630+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
631+ , Box.vcat Box.left (map typeAtomAsBox ts)
633+ , line "is an orphan instance."
626 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
634 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
627 , line "Consider moving the instance, if possible, or using a newtype wrapper."
635 , line "Consider moving the instance, if possible, or using a newtype wrapper."
629− goSimple InvalidNewtype =
637+ renderSimpleErrorMessage InvalidNewtype =
630 line "Newtypes must define a single constructor with a single argument"
638 line "Newtypes must define a single constructor with a single argument"
631− goSimple (InvalidInstanceHead ty) =
639+ renderSimpleErrorMessage (InvalidInstanceHead ty) =
632 paras [ line "Invalid type in class instance head:"
640 paras [ line "Invalid type in class instance head:"
633− , indent $ line $ prettyPrintType ty
641+ , indent $ typeAsBox ty
635− goSimple (TransitiveExportError x ys) =
643+ renderSimpleErrorMessage (TransitiveExportError x ys) =
636 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
644 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
637 : map (line . prettyPrintExport) ys
645 : map (line . prettyPrintExport) ys
638− goSimple (ShadowedName nm) =
646+ renderSimpleErrorMessage (ShadowedName nm) =
639 line $ "Name '" ++ showIdent nm ++ "' was shadowed"
647 line $ "Name '" ++ showIdent nm ++ "' was shadowed"
640− goSimple (ShadowedTypeVar tv) =
648+ renderSimpleErrorMessage (ShadowedTypeVar tv) =
641 line $ "Type variable '" ++ tv ++ "' was shadowed"
649 line $ "Type variable '" ++ tv ++ "' was shadowed"
642− goSimple (UnusedTypeVar tv) =
650+ renderSimpleErrorMessage (UnusedTypeVar tv) =
643 line $ "Type variable '" ++ tv ++ "' was declared but not used"
651 line $ "Type variable '" ++ tv ++ "' was declared but not used"
644− goSimple (ClassOperator className opName) =
652+ renderSimpleErrorMessage (ClassOperator className opName) =
645 paras [ line $ "Class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
653 paras [ line $ "Class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
646− , indent $ line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
654+ , line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
647− , indent $ line $ showIdent opName ++ " = someMember"
655+ , indent . line $ showIdent opName ++ " = someMember"
649− goSimple (MisleadingEmptyTypeImport mn name) =
657+ renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
650 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors"
658 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors"
651− goSimple (ImportHidingModule name) =
659+ renderSimpleErrorMessage (ImportHidingModule name) =
652 line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
660 line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
653− goSimple (WildcardInferredType ty) =
661+ renderSimpleErrorMessage (WildcardInferredType ty) =
654− line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
662+ paras [ line "The wildcard type definition has the inferred type "
663+ , indent $ typeAsBox ty
665+ renderSimpleErrorMessage (MissingTypeDeclaration ident) =
666+ paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
667+ , line "It is good practice to provide type declarations as a form of documentation."
668+ , line "Consider using a type wildcard to display the inferred type:"
669+ , indent $ line $ showIdent ident ++ " :: _"
655− goSimple (NotExhaustivePattern bs b) =
671+ renderSimpleErrorMessage (NotExhaustivePattern bs b) =
656 paras $ [ line "A case expression could not be determined to cover all inputs."
672 paras $ [ line "A case expression could not be determined to cover all inputs."
657 , line "The following additional cases are required to cover all inputs:\n"
673 , line "The following additional cases are required to cover all inputs:\n"
658 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
674 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
660 [ line "..." | not b ]
676 [ line "..." | not b ]
661− goSimple (OverlappingPattern bs b) =
677+ renderSimpleErrorMessage (OverlappingPattern bs b) =
662 paras $ [ line "A case expression contains unreachable cases:\n"
678 paras $ [ line "A case expression contains unreachable cases:\n"
663 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
679 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
665 [ line "..." | not b ]
681 [ line "..." | not b ]
666− goSimple IncompleteExhaustivityCheck =
682+ renderSimpleErrorMessage IncompleteExhaustivityCheck =
667 paras [ line "An exhaustivity check was abandoned due to too many possible cases."
683 paras [ line "An exhaustivity check was abandoned due to too many possible cases."
668 , line "You may want to decomposing your data types into smaller types."
684 , line "You may want to decomposing your data types into smaller types."
687+ renderHint :: ErrorMessageHint -> Box.Box
670− go (NotYetDefined names err) =
688+ renderHint (NotYetDefined names) =
671− paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
689+ line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
674− go (ErrorUnifyingTypes t1 t2 err) =
690+ renderHint (ErrorUnifyingTypes t1 t2) =
675 paras [ lineWithLevel "unifying type "
691 paras [ lineWithLevel "unifying type "
676− , indent $ line $ prettyPrintType t1
692+ , indent $ typeAsBox t1
677 , line "with type"
693 , line "with type"
678− , indent $ line $ prettyPrintType t2
694+ , indent $ typeAsBox t2
681− go (ErrorInExpression expr err) =
696+ renderHint (ErrorInExpression expr) =
682 paras [ lineWithLevel "in expression:"
697 paras [ lineWithLevel "in expression:"
683− , indent $ line $ prettyPrintValue expr
698+ , indent $ prettyPrintValue expr
686− go (ErrorInModule mn err) =
700+ renderHint (ErrorInModule mn) =
687 paras [ lineWithLevel $ "in module " ++ runModuleName mn ++ ":"
701 paras [ lineWithLevel $ "in module " ++ runModuleName mn ++ ":"
690− go (ErrorInSubsumption t1 t2 err) =
703+ renderHint (ErrorInSubsumption t1 t2) =
691 paras [ lineWithLevel "checking that type "
704 paras [ lineWithLevel "checking that type "
692− , indent $ line $ prettyPrintType t1
705+ , indent $ typeAsBox t1
693 , line "subsumes type"
706 , line "subsumes type"
694− , indent $ line $ prettyPrintType t2
707+ , indent $ typeAsBox t2
697− go (ErrorInInstance name ts err) =
709+ renderHint (ErrorInInstance nm ts) =
698− paras [ lineWithLevel $ "in type class instance " ++ showQualified runProperName name ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
710+ paras [ lineWithLevel "in type class instance"
699− , go err
711+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
712+ , Box.vcat Box.left (map typeAtomAsBox ts)
701− go (ErrorCheckingKind ty err) =
715+ renderHint (ErrorCheckingKind ty) =
702 paras [ lineWithLevel "checking kind of type "
716 paras [ lineWithLevel "checking kind of type "
703− , indent $ line $ prettyPrintType ty
717+ , indent $ typeAsBox ty
706− go (ErrorInferringType expr err) =
719+ renderHint (ErrorInferringType expr) =
707 paras [ lineWithLevel "inferring type of value "
720 paras [ lineWithLevel "inferring type of value "
708− , indent $ line $ prettyPrintValue expr
721+ , indent $ prettyPrintValue expr
711− go (ErrorCheckingType expr ty err) =
723+ renderHint (ErrorCheckingType expr ty) =
712 paras [ lineWithLevel "checking that value "
724 paras [ lineWithLevel "checking that value "
713− , indent $ line $ prettyPrintValue expr
725+ , indent $ prettyPrintValue expr
714 , line "has type"
726 , line "has type"
715− , indent $ line $ prettyPrintType ty
727+ , indent $ typeAsBox ty
718− go (ErrorInApplication f t a err) =
729+ renderHint (ErrorInApplication f t a) =
719 paras [ lineWithLevel "applying function"
730 paras [ lineWithLevel "applying function"
720− , indent $ line $ prettyPrintValue f
731+ , indent $ prettyPrintValue f
721 , line "of type"
732 , line "of type"
722− , indent $ line $ prettyPrintType t
733+ , indent $ typeAsBox t
723 , line "to argument"
734 , line "to argument"
724− , indent $ line $ prettyPrintValue a
735+ , indent $ prettyPrintValue a
727− go (ErrorInDataConstructor nm err) =
737+ renderHint (ErrorInDataConstructor nm) =
728− paras [ lineWithLevel $ "in data constructor " ++ runProperName nm ++ ":"
738+ lineWithLevel $ "in data constructor " ++ runProperName nm ++ ":"
731− go (ErrorInTypeConstructor nm err) =
739+ renderHint (ErrorInTypeConstructor nm) =
732− paras [ lineWithLevel $ "in type constructor " ++ runProperName nm ++ ":"
740+ lineWithLevel $ "in type constructor " ++ runProperName nm ++ ":"
735− go (ErrorInBindingGroup nms err) =
741+ renderHint (ErrorInBindingGroup nms) =
736− paras [ lineWithLevel $ "in binding group " ++ intercalate ", " (map showIdent nms) ++ ":"
742+ lineWithLevel $ "in binding group " ++ intercalate ", " (map showIdent nms) ++ ":"
739− go (ErrorInDataBindingGroup err) =
743+ renderHint ErrorInDataBindingGroup =
740− paras [ lineWithLevel "in data binding group:"
744+ lineWithLevel "in data binding group:"
743− go (ErrorInTypeSynonym name err) =
745+ renderHint (ErrorInTypeSynonym name) =
744− paras [ lineWithLevel $ "in type synonym " ++ runProperName name ++ ":"
746+ lineWithLevel $ "in type synonym " ++ runProperName name ++ ":"
747− go (ErrorInValueDeclaration n err) =
747+ renderHint (ErrorInValueDeclaration n) =
748− paras [ lineWithLevel $ "in value declaration " ++ showIdent n ++ ":"
748+ lineWithLevel $ "in value declaration " ++ showIdent n ++ ":"
751− go (ErrorInTypeDeclaration n err) =
749+ renderHint (ErrorInTypeDeclaration n) =
752− paras [ lineWithLevel $ "in type declaration for " ++ showIdent n ++ ":"
750+ lineWithLevel $ "in type declaration for " ++ showIdent n ++ ":"
755− go (ErrorInForeignImport nm err) =
751+ renderHint (ErrorInForeignImport nm) =
756− paras [ lineWithLevel $ "in foreign import " ++ showIdent nm ++ ":"
752+ lineWithLevel $ "in foreign import " ++ showIdent nm ++ ":"
759− go (PositionedError srcSpan err) =
753+ renderHint (PositionedError srcSpan) =
760− paras [ lineWithLevel $ "at " ++ displaySourceSpan srcSpan ++ ":"
754+ lineWithLevel $ "at " ++ displaySourceSpan srcSpan ++ ":"
763− go (SimpleErrorWrapper sem) = goSimple sem
765 lineWithLevel :: String -> Box.Box
756 lineWithLevel :: String -> Box.Box
766 lineWithLevel text = line $ show level ++ " " ++ text
757 lineWithLevel text = line $ show level ++ " " ++ text
@@ -770,23 +761,19 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
770 Error -> "error"
761 Error -> "error"
771 Warning -> "warning"
762 Warning -> "warning"
773− suggestions :: ErrorMessage -> [Box.Box]
764+ suggestions :: SimpleErrorMessage -> [Box.Box]
774− suggestions = suggestions' . unwrapErrorMessage
776− suggestions' (ConflictingImport nm im) = [ line $ "Possible fix: hide " ++ show nm ++ " when importing " ++ runModuleName im ++ ":"
765+ suggestions (ConflictingImport nm im) = [ line $ "Possible fix: hide " ++ show nm ++ " when importing " ++ runModuleName im ++ ":"
777 , indent . line $ "import " ++ runModuleName im ++ " hiding (" ++ nm ++ ")"
766 , indent . line $ "import " ++ runModuleName im ++ " hiding (" ++ nm ++ ")"
779− suggestions' (TypesDoNotUnify t1 t2)
768+ suggestions (TypesDoNotUnify t1 t2)
780− | isObject t1 && isFunction t2 = [line "Note that function composition in PureScript is defined using (<<<)"]
769+ | isObject t1 && isFunction t2 = [line "Note that function composition in PureScript is defined using (<<<)"]
781− | otherwise = []
770+ | otherwise = []
782− suggestions' _ = []
771+ suggestions _ = []
784 paras :: [Box.Box] -> Box.Box
773 paras :: [Box.Box] -> Box.Box
785 paras = Box.vcat Box.left
774 paras = Box.vcat Box.left
788 -- Pretty print and export declaration
776 -- Pretty print and export declaration
790 prettyPrintExport :: DeclarationRef -> String
777 prettyPrintExport :: DeclarationRef -> String
791 prettyPrintExport (TypeRef pn _) = runProperName pn
778 prettyPrintExport (TypeRef pn _) = runProperName pn
792 prettyPrintExport (ValueRef ident) = showIdent ident
779 prettyPrintExport (ValueRef ident) = showIdent ident
@@ -795,38 +782,44 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
795 prettyPrintExport (ModuleRef name) = "module " ++ runModuleName name
782 prettyPrintExport (ModuleRef name) = "module " ++ runModuleName name
796 prettyPrintExport (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
783 prettyPrintExport (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
798− -- |
785+ -- Hints get added at the front, so we need to reverse them before rendering
799− -- Simplify an error message
786+ reverseHints :: ErrorMessage -> ErrorMessage
800− --
787+ reverseHints (ErrorMessage hints simple) = ErrorMessage (reverse hints) simple
789+ -- | Put positional hints at the front of the list
801− simplifyErrorMessage :: ErrorMessage -> ErrorMessage
790+ positionHintsFirst :: ErrorMessage -> ErrorMessage
802− simplifyErrorMessage = unwrap Nothing
791+ positionHintsFirst (ErrorMessage hints simple) = ErrorMessage (uncurry (++) $ partition (isPositionHint . hintCategory) hints) simple
804− unwrap :: Maybe SourceSpan -> ErrorMessage -> ErrorMessage
793+ isPositionHint :: HintCategory -> Bool
805− unwrap pos (ErrorInExpression _ err) = unwrap pos err
794+ isPositionHint PositionHint = True
806− unwrap pos (ErrorInInstance name ts err) = ErrorInInstance name ts (unwrap pos err)
795+ isPositionHint OtherHint = True
807− unwrap pos (ErrorInSubsumption t1 t2 err) = ErrorInSubsumption t1 t2 (unwrap pos err)
796+ isPositionHint _ = False
808− unwrap pos (ErrorUnifyingTypes _ _ err) = unwrap pos err
809− unwrap pos (ErrorInferringType _ err) = unwrap pos err
810− unwrap pos (ErrorCheckingType _ _ err) = unwrap pos err
811− unwrap pos (ErrorCheckingKind ty err) = ErrorCheckingKind ty (unwrap pos err)
812− unwrap pos (ErrorInModule mn err) = ErrorInModule mn (unwrap pos err)
813− unwrap pos (ErrorInApplication _ _ _ err) = unwrap pos err
814− unwrap pos (ErrorInDataConstructor nm err) = ErrorInDataConstructor nm (unwrap pos err)
815− unwrap pos (ErrorInTypeConstructor nm err) = ErrorInTypeConstructor nm (unwrap pos err)
816− unwrap pos (ErrorInBindingGroup nms err) = ErrorInBindingGroup nms (unwrap pos err)
817− unwrap pos (ErrorInDataBindingGroup err) = ErrorInDataBindingGroup (unwrap pos err)
818− unwrap pos (ErrorInTypeSynonym nm err) = ErrorInTypeSynonym nm (unwrap pos err)
819− unwrap pos (ErrorInValueDeclaration nm err) = ErrorInValueDeclaration nm (unwrap pos err)
820− unwrap pos (ErrorInTypeDeclaration nm err) = ErrorInTypeDeclaration nm (unwrap pos err)
821− unwrap pos (ErrorInForeignImport nm err) = ErrorInForeignImport nm (unwrap pos err)
822− unwrap pos (NotYetDefined ns err) = NotYetDefined ns (unwrap pos err)
823− unwrap _ (PositionedError pos err) = unwrap (Just pos) err
824− unwrap pos other = wrap pos other
826− wrap :: Maybe SourceSpan -> ErrorMessage -> ErrorMessage
828− wrap (Just pos) = PositionedError pos
798+ -- | Simplify an error message
799+ simplifyErrorMessage :: ErrorMessage -> ErrorMessage
800+ simplifyErrorMessage (ErrorMessage hints simple) = ErrorMessage (simplifyHints hints) simple
802+ -- Take the last instance of each "hint category"
803+ simplifyHints :: [ErrorMessageHint] -> [ErrorMessageHint]
804+ simplifyHints = reverse . nubBy categoriesEqual . reverse
806+ -- Don't remove hints in the "other" category
807+ categoriesEqual :: ErrorMessageHint -> ErrorMessageHint -> Bool
808+ categoriesEqual x y =
809+ case (hintCategory x, hintCategory y) of
810+ (OtherHint, _) -> False
811+ (_, OtherHint) -> False
812+ (c1, c2) -> c1 == c2
814+ hintCategory :: ErrorMessageHint -> HintCategory
815+ hintCategory ErrorCheckingType{} = ExprHint
816+ hintCategory ErrorInferringType{} = ExprHint
817+ hintCategory ErrorInExpression{} = ExprHint
818+ hintCategory ErrorUnifyingTypes{} = CheckHint
819+ hintCategory ErrorInSubsumption{} = CheckHint
820+ hintCategory ErrorInApplication{} = CheckHint
821+ hintCategory PositionedError{} = PositionHint
822+ hintCategory _ = OtherHint
832-- Pretty print multiple errors
825-- Pretty print multiple errors
@@ -842,11 +835,11 @@ prettyPrintMultipleWarnings full = renderBox . prettyPrintMultipleWarningsBox fu
843-- | Pretty print warnings as a Box
836-- | Pretty print warnings as a Box
844prettyPrintMultipleWarningsBox :: Bool -> MultipleErrors -> Box.Box
837prettyPrintMultipleWarningsBox :: Bool -> MultipleErrors -> Box.Box
845−prettyPrintMultipleWarningsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Warning "Warning found:" "Multiple warnings found:" full
838+prettyPrintMultipleWarningsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Warning "Warning found:" "Warning" full
847-- | Pretty print errors as a Box
840-- | Pretty print errors as a Box
848prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> Box.Box
841prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> Box.Box
849−prettyPrintMultipleErrorsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Error "Error found:" "Multiple errors found:" full
842+prettyPrintMultipleErrorsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Error "Error found:" "Error" full
851prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> State UnknownMap Box.Box
844prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> State UnknownMap Box.Box
852prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
845prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
@@ -856,11 +849,12 @@ prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
858prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
851prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
859− result <- forM es $ liftM (Box.moveRight 2) . prettyPrintSingleError full level
852+ result <- forM es $ prettyPrintSingleError full level
860− return $
853+ return $ Box.vsep 1 Box.left $ concat $ zipWith withIntro [1 :: Int ..] result
861− Box.vcat Box.left [ Box.text intro
854+ where
862− , Box.vsep 1 Box.left result
855+ withIntro i err = [ Box.text (intro ++ " " ++ show i ++ " of " ++ show (length es) ++ ":")
856+ , Box.moveRight 2 err
865-- | Pretty print a Parsec ParseError as a Box
859-- | Pretty print a Parsec ParseError as a Box
866prettyPrintParseError :: P.ParseError -> Box.Box
860prettyPrintParseError :: P.ParseError -> Box.Box
@@ -910,8 +904,9 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
911 clean = nub . filter (not . null)
905 clean = nub . filter (not . null)
907+-- | Indent to the right, and pad on top and bottom.
913indent :: Box.Box -> Box.Box
908indent :: Box.Box -> Box.Box
914−indent = Box.moveRight 2
909+indent = Box.moveUp 1 . Box.moveDown 1 . Box.moveRight 2
916line :: String -> Box.Box
911line :: String -> Box.Box
917line = Box.text
912line = Box.text
@@ -951,8 +946,7 @@ warnAndRethrowWithPosition :: (MonadError MultipleErrors m, MonadWriter Multiple
951warnAndRethrowWithPosition pos = rethrowWithPosition pos . warnWithPosition pos
946warnAndRethrowWithPosition pos = rethrowWithPosition pos . warnWithPosition pos
953withPosition :: SourceSpan -> ErrorMessage -> ErrorMessage
948withPosition :: SourceSpan -> ErrorMessage -> ErrorMessage
954−withPosition _ (PositionedError pos err) = withPosition pos err
949+withPosition pos (ErrorMessage hints se) = ErrorMessage (PositionedError pos : hints) se
955−withPosition pos err = PositionedError pos err
958-- Collect errors in in parallel
952-- Collect errors in in parallel