@@ -427,7 +427,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
428 goSimple (ErrorParsingExterns err) =
428 goSimple (ErrorParsingExterns err) =
429 paras [ lineWithLevel "parsing externs files: "
429 paras [ lineWithLevel "parsing externs files: "
430− , indent . prettyPrintParseError $ err
430+ , prettyPrintParseError err
432 goSimple (ErrorParsingFFIModule path) =
432 goSimple (ErrorParsingFFIModule path) =
433 paras [ line "Unable to parse module from FFI file: "
433 paras [ line "Unable to parse module from FFI file: "
@@ -435,7 +435,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
436 goSimple (ErrorParsingModule err) =
436 goSimple (ErrorParsingModule err) =
437 paras [ line "Unable to parse module: "
437 paras [ line "Unable to parse module: "
438− , indent . prettyPrintParseError $ err
438+ , prettyPrintParseError err
440 goSimple (MissingFFIModule mn) =
440 goSimple (MissingFFIModule mn) =
441 line $ "Missing FFI implementations for module " ++ runModuleName mn
441 line $ "Missing FFI implementations for module " ++ runModuleName mn
@@ -444,8 +444,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
444 , indent . line $ path
444 , indent . line $ path
446 goSimple (MultipleFFIModules mn paths) =
446 goSimple (MultipleFFIModules mn paths) =
447− paras $ [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": " ]
447+ paras [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
448− ++ map (indent . line) paths
448+ , indent . paras $ map line paths
449 goSimple (InvalidExternsFile path) =
450 goSimple (InvalidExternsFile path) =
450 paras [ line "Externs file is invalid: "
451 paras [ line "Externs file is invalid: "
451 , indent . line $ path
452 , indent . line $ path
@@ -462,11 +463,11 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
462 line "Overlapping names in let binding."
463 line "Overlapping names in let binding."
463 goSimple (InfiniteType ty) =
464 goSimple (InfiniteType ty) =
464 paras [ line "An infinite type was inferred for an expression: "
465 paras [ line "An infinite type was inferred for an expression: "
465− , indent $ line $ prettyPrintType ty
466+ , indent $ typeAsBox ty
467 goSimple (InfiniteKind ki) =
468 goSimple (InfiniteKind ki) =
468 paras [ line "An infinite kind was inferred for a type: "
469 paras [ line "An infinite kind was inferred for a type: "
469− , indent $ line $ prettyPrintKind ki
470+ , indent $ kindAsBox ki
471 goSimple (MultipleFixities name) =
472 goSimple (MultipleFixities name) =
472 line $ "Multiple fixity declarations for " ++ showIdent name
473 line $ "Multiple fixity declarations for " ++ showIdent name
@@ -475,8 +476,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
475 goSimple (OrphanFixityDeclaration op) =
476 goSimple (OrphanFixityDeclaration op) =
476 line $ "Orphan fixity declaration for " ++ show op
477 line $ "Orphan fixity declaration for " ++ show op
477 goSimple (RedefinedModule name filenames) =
478 goSimple (RedefinedModule name filenames) =
478− paras $ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
479+ paras [ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
479− : map (indent . line . displaySourceSpan) filenames
480+ , indent . paras $ map (line . displaySourceSpan) filenames
480 goSimple (RedefinedIdent name) =
482 goSimple (RedefinedIdent name) =
481 line $ "Name " ++ showIdent name ++ " has been defined multiple times"
483 line $ "Name " ++ showIdent name ++ " has been defined multiple times"
482 goSimple (UnknownModule mn) =
484 goSimple (UnknownModule mn) =
@@ -548,43 +550,60 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
548 goSimple (EscapedSkolem binding) =
550 goSimple (EscapedSkolem binding) =
549 paras $ [ line "A type variable has escaped its scope." ]
551 paras $ [ line "A type variable has escaped its scope." ]
550 <> foldMap (\expr -> [ line "Relevant expression: "
552 <> foldMap (\expr -> [ line "Relevant expression: "
551− , indent $ line $ prettyPrintValue expr
553+ , indent $ prettyPrintValue expr
552 ]) binding
554 ]) binding
553 goSimple (TypesDoNotUnify t1 t2)
555 goSimple (TypesDoNotUnify t1 t2)
554 = paras [ line "Cannot unify type"
556 = paras [ line "Cannot unify type"
555− , indent $ line $ prettyPrintType t1
557+ , indent $ typeAsBox t1
556 , line "with type"
558 , line "with type"
557− , indent $ line $ prettyPrintType t2
559+ , indent $ typeAsBox t2
559 goSimple (KindsDoNotUnify k1 k2) =
561 goSimple (KindsDoNotUnify k1 k2) =
560 paras [ line "Cannot unify kind"
562 paras [ line "Cannot unify kind"
561− , indent $ line $ prettyPrintKind k1
563+ , indent $ kindAsBox k1
562 , line "with kind"
564 , line "with kind"
563− , indent $ line $ prettyPrintKind k2
565+ , indent $ kindAsBox k2
565 goSimple (ConstrainedTypeUnified t1 t2) =
567 goSimple (ConstrainedTypeUnified t1 t2) =
566 paras [ line "Cannot unify constrained type"
568 paras [ line "Cannot unify constrained type"
567− , indent $ line $ prettyPrintType t1
569+ , indent $ typeAsBox t1
568 , line "with type"
570 , line "with type"
569− , indent $ line $ prettyPrintType t2
571+ , indent $ typeAsBox t2
571 goSimple (OverlappingInstances nm ts (d : ds)) =
573 goSimple (OverlappingInstances nm ts (d : ds)) =
572− paras [ line $ "Overlapping instances found for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
574+ paras [ line "Overlapping instances found for"
575+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
576+ , Box.vcat Box.left (map typeAtomAsBox ts)
578+ , line "The following instances were found:"
573 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
579 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
575 goSimple OverlappingInstances{} = error "OverlappingInstances: empty instance list"
581 goSimple OverlappingInstances{} = error "OverlappingInstances: empty instance list"
576 goSimple (NoInstanceFound nm ts) =
582 goSimple (NoInstanceFound nm ts) =
583+ paras [ line "No instance found for"
577− line $ "No instance found for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts)
584+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
585+ , Box.vcat Box.left (map typeAtomAsBox ts)
578 goSimple (PossiblyInfiniteInstance nm ts) =
588 goSimple (PossiblyInfiniteInstance nm ts) =
579− line $ "Instance for " ++ showQualified runProperName nm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ " is possibly infinite."
589+ paras [ line "Instance for"
590+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
591+ , Box.vcat Box.left (map typeAtomAsBox ts)
593+ , line "is possibly infinite."
580 goSimple (CannotDerive nm ts) =
595 goSimple (CannotDerive nm ts) =
596+ paras [ line "Cannot derive an instance for"
581− line $ "Cannot derive " ++ showQualified runProperName nm ++ " instance for " ++ unwords (map prettyPrintTypeAtom ts)
597+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
598+ , Box.vcat Box.left (map typeAtomAsBox ts)
582 goSimple (CannotFindDerivingType nm) =
601 goSimple (CannotFindDerivingType nm) =
583 line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
602 line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
584 goSimple (DuplicateLabel l expr) =
603 goSimple (DuplicateLabel l expr) =
585 paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
604 paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
586 <> foldMap (\expr' -> [ line "Relevant expression: "
605 <> foldMap (\expr' -> [ line "Relevant expression: "
587− , indent $ line $ prettyPrintValue expr'
606+ , indent $ prettyPrintValue expr'
589 goSimple (DuplicateTypeArgument name) =
608 goSimple (DuplicateTypeArgument name) =
590 line $ "Duplicate type argument " ++ show name
609 line $ "Duplicate type argument " ++ show name
@@ -600,29 +619,40 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
600 line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
619 line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
601 goSimple (ExpectedType ty kind) =
620 goSimple (ExpectedType ty kind) =
602 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
621 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."
622+ , line "The error arises from the type"
623+ , indent $ typeAsBox ty
624+ , line "having the kind"
625+ , indent $ kindAsBox kind
605 goSimple (IncorrectConstructorArity nm) =
628 goSimple (IncorrectConstructorArity nm) =
606 line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
629 line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
607 goSimple SubsumptionCheckFailed = line "Unable to check type subsumption"
630 goSimple SubsumptionCheckFailed = line "Unable to check type subsumption"
608 goSimple (ExprDoesNotHaveType expr ty) =
631 goSimple (ExprDoesNotHaveType expr ty) =
609 paras [ line "Expression"
632 paras [ line "Expression"
610− , indent $ line $ prettyPrintValue expr
633+ , indent $ prettyPrintValue expr
611 , line "does not have type"
634 , line "does not have type"
612− , indent $ line $ prettyPrintType ty
635+ , indent $ typeAsBox ty
614 goSimple (PropertyIsMissing prop row) =
637 goSimple (PropertyIsMissing prop row) =
639+ , indent $ prettyPrintRowWith '(' ')' row
615− line $ "Row " ++ prettyPrintRow row ++ " lacks required property " ++ show prop
640+ , line $ "lacks required property " ++ show prop
616 goSimple (CannotApplyFunction fn arg) =
642 goSimple (CannotApplyFunction fn arg) =
617 paras [ line "Cannot apply function of type"
643 paras [ line "Cannot apply function of type"
618− , indent $ line $ prettyPrintType fn
644+ , indent $ typeAsBox fn
619 , line "to argument"
645 , line "to argument"
620− , indent $ line $ prettyPrintValue arg
646+ , indent $ prettyPrintValue arg
622 goSimple TypeSynonymInstance =
648 goSimple TypeSynonymInstance =
623 line "Type synonym instances are disallowed"
649 line "Type synonym instances are disallowed"
624 goSimple (OrphanInstance nm cnm ts) =
650 goSimple (OrphanInstance nm cnm ts) =
625− paras [ line $ "Instance " ++ showIdent nm ++ " for " ++ showQualified runProperName cnm ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ " is an orphan instance."
651+ paras [ line $ "Instance " ++ showIdent nm ++ " for "
652+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
653+ , Box.vcat Box.left (map typeAtomAsBox ts)
655+ , 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."
656 , 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."
657 , line "Consider moving the instance, if possible, or using a newtype wrapper."
@@ -630,7 +660,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
630 line "Newtypes must define a single constructor with a single argument"
660 line "Newtypes must define a single constructor with a single argument"
631 goSimple (InvalidInstanceHead ty) =
661 goSimple (InvalidInstanceHead ty) =
632 paras [ line "Invalid type in class instance head:"
662 paras [ line "Invalid type in class instance head:"
633− , indent $ line $ prettyPrintType ty
663+ , indent $ typeAsBox ty
635 goSimple (TransitiveExportError x ys) =
665 goSimple (TransitiveExportError x ys) =
636 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
666 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
@@ -643,15 +673,17 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
643 line $ "Type variable '" ++ tv ++ "' was declared but not used"
673 line $ "Type variable '" ++ tv ++ "' was declared but not used"
644 goSimple (ClassOperator className opName) =
674 goSimple (ClassOperator className opName) =
645 paras [ line $ "Class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
675 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:"
676+ , 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"
677+ , indent . line $ showIdent opName ++ " = someMember"
649 goSimple (MisleadingEmptyTypeImport mn name) =
679 goSimple (MisleadingEmptyTypeImport mn name) =
650 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors"
680 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors"
651 goSimple (ImportHidingModule name) =
681 goSimple (ImportHidingModule name) =
652 line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
682 line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
653 goSimple (WildcardInferredType ty) =
683 goSimple (WildcardInferredType ty) =
654− line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
684+ paras [ line "The wildcard type definition has the inferred type "
685+ , indent $ typeAsBox ty
655 goSimple (NotExhaustivePattern bs b) =
687 goSimple (NotExhaustivePattern bs b) =
656 paras $ [ line "A case expression could not be determined to cover all inputs."
688 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"
689 , line "The following additional cases are required to cover all inputs:\n"
@@ -669,18 +701,18 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
670 go (NotYetDefined names err) =
702 go (NotYetDefined names err) =
671 paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
703 paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
672− , indent $ go err
704+ , go err
674 go (ErrorUnifyingTypes t1 t2 err) =
706 go (ErrorUnifyingTypes t1 t2 err) =
675 paras [ lineWithLevel "unifying type "
707 paras [ lineWithLevel "unifying type "
676− , indent $ line $ prettyPrintType t1
708+ , indent $ typeAsBox t1
677 , line "with type"
709 , line "with type"
678− , indent $ line $ prettyPrintType t2
710+ , indent $ typeAsBox t2
681 go (ErrorInExpression expr err) =
713 go (ErrorInExpression expr err) =
682 paras [ lineWithLevel "in expression:"
714 paras [ lineWithLevel "in expression:"
683− , indent $ line $ prettyPrintValue expr
715+ , indent $ prettyPrintValue expr
686 go (ErrorInModule mn err) =
718 go (ErrorInModule mn err) =
@@ -689,39 +721,42 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
690 go (ErrorInSubsumption t1 t2 err) =
722 go (ErrorInSubsumption t1 t2 err) =
691 paras [ lineWithLevel "checking that type "
723 paras [ lineWithLevel "checking that type "
692− , indent $ line $ prettyPrintType t1
724+ , indent $ typeAsBox t1
693 , line "subsumes type"
725 , line "subsumes type"
694− , indent $ line $ prettyPrintType t2
726+ , indent $ typeAsBox t2
697− go (ErrorInInstance name ts err) =
729+ go (ErrorInInstance nm ts err) =
698− paras [ lineWithLevel $ "in type class instance " ++ showQualified runProperName name ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":"
730+ paras [ lineWithLevel "in type class instance"
731+ , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
732+ , Box.vcat Box.left (map typeAtomAsBox ts)
701 go (ErrorCheckingKind ty err) =
736 go (ErrorCheckingKind ty err) =
702 paras [ lineWithLevel "checking kind of type "
737 paras [ lineWithLevel "checking kind of type "
703− , indent $ line $ prettyPrintType ty
738+ , indent $ typeAsBox ty
706 go (ErrorInferringType expr err) =
741 go (ErrorInferringType expr err) =
707 paras [ lineWithLevel "inferring type of value "
742 paras [ lineWithLevel "inferring type of value "
708− , indent $ line $ prettyPrintValue expr
743+ , indent $ prettyPrintValue expr
711 go (ErrorCheckingType expr ty err) =
746 go (ErrorCheckingType expr ty err) =
712 paras [ lineWithLevel "checking that value "
747 paras [ lineWithLevel "checking that value "
713− , indent $ line $ prettyPrintValue expr
748+ , indent $ prettyPrintValue expr
714 , line "has type"
749 , line "has type"
715− , indent $ line $ prettyPrintType ty
750+ , indent $ typeAsBox ty
718 go (ErrorInApplication f t a err) =
753 go (ErrorInApplication f t a err) =
719 paras [ lineWithLevel "applying function"
754 paras [ lineWithLevel "applying function"
720− , indent $ line $ prettyPrintValue f
755+ , indent $ prettyPrintValue f
721 , line "of type"
756 , line "of type"
722− , indent $ line $ prettyPrintType t
757+ , indent $ typeAsBox t
723 , line "to argument"
758 , line "to argument"
724− , indent $ line $ prettyPrintValue a
759+ , indent $ prettyPrintValue a
727 go (ErrorInDataConstructor nm err) =
762 go (ErrorInDataConstructor nm err) =
@@ -758,7 +793,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
759 go (PositionedError srcSpan err) =
794 go (PositionedError srcSpan err) =
760 paras [ lineWithLevel $ "at " ++ displaySourceSpan srcSpan ++ ":"
795 paras [ lineWithLevel $ "at " ++ displaySourceSpan srcSpan ++ ":"
761− , indent $ go err
796+ , go err
763 go (SimpleErrorWrapper sem) = goSimple sem
798 go (SimpleErrorWrapper sem) = goSimple sem
@@ -842,11 +877,11 @@ prettyPrintMultipleWarnings full = renderBox . prettyPrintMultipleWarningsBox fu
843-- | Pretty print warnings as a Box
878-- | Pretty print warnings as a Box
844prettyPrintMultipleWarningsBox :: Bool -> MultipleErrors -> Box.Box
879prettyPrintMultipleWarningsBox :: Bool -> MultipleErrors -> Box.Box
845−prettyPrintMultipleWarningsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Warning "Warning found:" "Multiple warnings found:" full
880+prettyPrintMultipleWarningsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Warning "Warning found:" "Warning" full
847-- | Pretty print errors as a Box
882-- | Pretty print errors as a Box
848prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> Box.Box
883prettyPrintMultipleErrorsBox :: Bool -> MultipleErrors -> Box.Box
849−prettyPrintMultipleErrorsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Error "Error found:" "Multiple errors found:" full
884+prettyPrintMultipleErrorsBox full = flip evalState M.empty . prettyPrintMultipleErrorsWith Error "Error found:" "Error" full
851prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> State UnknownMap Box.Box
886prettyPrintMultipleErrorsWith :: Level -> String -> String -> Bool -> MultipleErrors -> State UnknownMap Box.Box
852prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
887prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
@@ -856,11 +891,12 @@ prettyPrintMultipleErrorsWith level intro _ full (MultipleErrors [e]) = do
858prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
893prettyPrintMultipleErrorsWith level _ intro full (MultipleErrors es) = do
859− result <- forM es $ liftM (Box.moveRight 2) . prettyPrintSingleError full level
894+ result <- forM es $ prettyPrintSingleError full level
860− return $
895+ return $ Box.vsep 1 Box.left $ concat $ zipWith withIntro [1 :: Int ..] result
861− Box.vcat Box.left [ Box.text intro
896+ where
862− , Box.vsep 1 Box.left result
897+ withIntro i err = [ Box.text (intro ++ " " ++ show i ++ " of " ++ show (length es) ++ ":")
898+ , Box.moveRight 2 err
865-- | Pretty print a Parsec ParseError as a Box
901-- | Pretty print a Parsec ParseError as a Box
866prettyPrintParseError :: P.ParseError -> Box.Box
902prettyPrintParseError :: P.ParseError -> Box.Box
@@ -910,8 +946,9 @@ prettyPrintParseErrorMessages msgOr msgUnknown msgExpecting msgUnExpected msgEnd
911 clean = nub . filter (not . null)
947 clean = nub . filter (not . null)
949+-- | Indent to the right, and pad on top and bottom.
913indent :: Box.Box -> Box.Box
950indent :: Box.Box -> Box.Box
914−indent = Box.moveRight 2
951+indent = Box.moveUp 1 . Box.moveDown 1 . Box.moveRight 2
916line :: String -> Box.Box
953line :: String -> Box.Box
917line = Box.text
954line = Box.text