@@ -24,6 +24,7 @@ import Control.Arrow ((&&&))
24import Language.PureScript.Crash
24import Language.PureScript.Crash
25import Language.PureScript.AST
25import Language.PureScript.AST
26import Language.PureScript.Pretty
26import Language.PureScript.Pretty
27+import Language.PureScript.Pretty.Common (before)
27import Language.PureScript.Types
28import Language.PureScript.Types
28import Language.PureScript.Names
29import Language.PureScript.Names
29import Language.PureScript.Kinds
30import Language.PureScript.Kinds
@@ -128,6 +129,7 @@ data SimpleErrorMessage
128 | UnusedDctorImport (ProperName 'TypeName)
129 | UnusedDctorImport (ProperName 'TypeName)
129 | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
130 | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
130 | DeprecatedOperatorDecl String
131 | DeprecatedOperatorDecl String
132+ | DeprecatedOperatorSection Expr (Either Expr Expr)
131 | DeprecatedQualifiedSyntax ModuleName ModuleName
133 | DeprecatedQualifiedSyntax ModuleName ModuleName
132 | DeprecatedClassImport ModuleName (ProperName 'ClassName)
134 | DeprecatedClassImport ModuleName (ProperName 'ClassName)
133 | DeprecatedClassExport (ProperName 'ClassName)
135 | DeprecatedClassExport (ProperName 'ClassName)
@@ -142,6 +144,7 @@ data SimpleErrorMessage
142 | ImplicitImport ModuleName [DeclarationRef]
144 | ImplicitImport ModuleName [DeclarationRef]
143 | HidingImport ModuleName [DeclarationRef]
145 | HidingImport ModuleName [DeclarationRef]
144 | CaseBinderLengthDiffers Int [Binder]
146 | CaseBinderLengthDiffers Int [Binder]
147+ | IncorrectAnonymousArgument
145 deriving (Show)
148 deriving (Show)
147-- | Error message hints, providing more detailed information about failure.
150-- | Error message hints, providing more detailed information about failure.
@@ -303,6 +306,7 @@ errorCode em = case unwrapErrorMessage em of
303 UnusedDctorImport{} -> "UnusedDctorImport"
306 UnusedDctorImport{} -> "UnusedDctorImport"
304 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
307 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
305 DeprecatedOperatorDecl{} -> "DeprecatedOperatorDecl"
308 DeprecatedOperatorDecl{} -> "DeprecatedOperatorDecl"
309+ DeprecatedOperatorSection{} -> "DeprecatedOperatorSection"
306 DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
310 DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
307 DeprecatedClassImport{} -> "DeprecatedClassImport"
311 DeprecatedClassImport{} -> "DeprecatedClassImport"
308 DeprecatedClassExport{} -> "DeprecatedClassExport"
312 DeprecatedClassExport{} -> "DeprecatedClassExport"
@@ -317,6 +321,7 @@ errorCode em = case unwrapErrorMessage em of
317 ImplicitImport{} -> "ImplicitImport"
321 ImplicitImport{} -> "ImplicitImport"
318 HidingImport{} -> "HidingImport"
322 HidingImport{} -> "HidingImport"
319 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
323 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
324+ IncorrectAnonymousArgument -> "IncorrectAnonymousArgument"
322-- A stack trace for an error
327-- A stack trace for an error
@@ -424,7 +429,7 @@ wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ error
424-- TODO Other possible suggestions:
429-- TODO Other possible suggestions:
425-- WildcardInferredType - source span not small enough
430-- WildcardInferredType - source span not small enough
426-- DuplicateSelectiveImport - would require 2 ranges to remove and 1 insert
431-- DuplicateSelectiveImport - would require 2 ranges to remove and 1 insert
427−-- DeprecatedClassExport, DeprecatedClassImport, would want to replace smaller span?
432+-- DeprecatedClassExport, DeprecatedClassImport, DeprecatedOperatorSection, would want to replace smaller span?
428errorSuggestion :: SimpleErrorMessage -> Maybe ErrorSuggestion
433errorSuggestion :: SimpleErrorMessage -> Maybe ErrorSuggestion
429errorSuggestion err = case err of
434errorSuggestion err = case err of
430 UnusedImport{} -> emptySuggestion
435 UnusedImport{} -> emptySuggestion
@@ -798,7 +803,7 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
798 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
803 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
799 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors."
804 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors."
800 renderSimpleErrorMessage (ImportHidingModule name) =
805 renderSimpleErrorMessage (ImportHidingModule name) =
801− paras [ line $ "'hiding' imports cannot be used to hide modules."
806+ paras [ line "'hiding' imports cannot be used to hide modules."
802 , line $ "An attempt was made to hide the import of " ++ runModuleName name
807 , line $ "An attempt was made to hide the import of " ++ runModuleName name
804 renderSimpleErrorMessage (WildcardInferredType ty) =
809 renderSimpleErrorMessage (WildcardInferredType ty) =
@@ -812,14 +817,14 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
812 , indent $ typeAsBox ty
817 , indent $ typeAsBox ty
814 renderSimpleErrorMessage (NotExhaustivePattern bs b) =
819 renderSimpleErrorMessage (NotExhaustivePattern bs b) =
815− paras $ [ line "A case expression could not be determined to cover all inputs."
820+ paras [ line "A case expression could not be determined to cover all inputs."
816− , line "The following additional cases are required to cover all inputs:\n"
821+ , line "The following additional cases are required to cover all inputs:\n"
817− , indent $ paras $
822+ , indent $ paras $
818− [ Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs)) ]
823+ [ Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs)) ]
819− ++ [ line "..." | not b ]
824+ ++ [ line "..." | not b ]
820− , line "Or alternatively, add a Partial constraint to the type of the enclosing value."
825+ , line "Or alternatively, add a Partial constraint to the type of the enclosing value."
821− , line "Non-exhaustive patterns for values without a `Partial` constraint will be disallowed in PureScript 0.9."
826+ , line "Non-exhaustive patterns for values without a `Partial` constraint will be disallowed in PureScript 0.9."
823 renderSimpleErrorMessage (OverlappingPattern bs b) =
828 renderSimpleErrorMessage (OverlappingPattern bs b) =
824 paras $ [ line "A case expression contains unreachable cases:\n"
829 paras $ [ line "A case expression contains unreachable cases:\n"
825 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
830 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
@@ -835,7 +840,7 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
835 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
840 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
836 paras [ line $ "The import of module " ++ runModuleName mn ++ " contains the following unused references:"
841 paras [ line $ "The import of module " ++ runModuleName mn ++ " contains the following unused references:"
837 , indent $ paras $ map line names
842 , indent $ paras $ map line names
838− , line $ "It could be replaced with:"
843+ , line "It could be replaced with:"
839 , indent $ line $ showSuggestion msg ]
844 , indent $ line $ showSuggestion msg ]
841 renderSimpleErrorMessage (UnusedDctorImport name) =
846 renderSimpleErrorMessage (UnusedDctorImport name) =
@@ -849,15 +854,39 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
849 paras [ line $ "The operator (" ++ name ++ ") was declared as a value rather than an alias for a named function."
854 paras [ line $ "The operator (" ++ name ++ ") was declared as a value rather than an alias for a named function."
850 , line "Operator aliases are declared by using a fixity declaration, for example:"
855 , line "Operator aliases are declared by using a fixity declaration, for example:"
851 , indent $ line $ "infixl 9 someFunction as " ++ name
856 , indent $ line $ "infixl 9 someFunction as " ++ name
852− , line $ "Support for value-declared operators will be removed in PureScript 0.9."
857+ , line "Support for value-declared operators will be removed in PureScript 0.9."
860+ renderSimpleErrorMessage (DeprecatedOperatorSection op val) =
861+ paras [ line "An operator section uses legacy syntax. Operator sections are now written using anonymous function syntax:"
862+ , indent $ foldr1 before $
866+ , prettyPrintValue valueDepth l
875+ , prettyPrintValue valueDepth r
878+ , line "Support for legacy operator sections will be removed in PureScript 0.9."
881+ renderOperator (PositionedValue _ _ ex) = renderOperator ex
882+ renderOperator (Var (Qualified _ (Op ident))) = line ident
883+ renderOperator other = Box.hcat Box.top [ line "`", prettyPrintValue valueDepth other, line "`" ]
855 renderSimpleErrorMessage (DeprecatedQualifiedSyntax name qualName) =
884 renderSimpleErrorMessage (DeprecatedQualifiedSyntax name qualName) =
856− paras [ line $ "Import uses the deprecated 'qualified' syntax:"
885+ paras [ line "Import uses the deprecated 'qualified' syntax:"
857 , indent $ line $ "import qualified " ++ runModuleName name ++ " as " ++ runModuleName qualName
886 , indent $ line $ "import qualified " ++ runModuleName name ++ " as " ++ runModuleName qualName
858 , line "Should instead use the form:"
887 , line "Should instead use the form:"
859 , indent $ line $ "import " ++ runModuleName name ++ " as " ++ runModuleName qualName
888 , indent $ line $ "import " ++ runModuleName name ++ " as " ++ runModuleName qualName
860− , line $ "The deprecated syntax will be removed in PureScript 0.9."
889+ , line "The deprecated syntax will be removed in PureScript 0.9."
863 renderSimpleErrorMessage (DeprecatedClassImport mn name) =
892 renderSimpleErrorMessage (DeprecatedClassImport mn name) =
@@ -865,15 +894,15 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
865 , indent $ line $ runProperName name
894 , indent $ line $ runProperName name
866 , line "Should instead use the form:"
895 , line "Should instead use the form:"
867 , indent $ line $ "class " ++ runProperName name
896 , indent $ line $ "class " ++ runProperName name
868− , line $ "The deprecated syntax will be removed in PureScript 0.9."
897+ , line "The deprecated syntax will be removed in PureScript 0.9."
871 renderSimpleErrorMessage (DeprecatedClassExport name) =
900 renderSimpleErrorMessage (DeprecatedClassExport name) =
872− paras [ line $ "Class export uses deprecated syntax that omits the 'class' keyword:"
901+ paras [ line "Class export uses deprecated syntax that omits the 'class' keyword:"
873 , indent $ line $ runProperName name
902 , indent $ line $ runProperName name
874 , line "Should instead use the form:"
903 , line "Should instead use the form:"
875 , indent $ line $ "class " ++ runProperName name
904 , indent $ line $ "class " ++ runProperName name
876− , line $ "The deprecated syntax will be removed in PureScript 0.9."
905+ , line "The deprecated syntax will be removed in PureScript 0.9."
879 renderSimpleErrorMessage (RedundantUnqualifiedImport name imp) =
908 renderSimpleErrorMessage (RedundantUnqualifiedImport name imp) =
@@ -915,9 +944,13 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
917 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
946 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
918− paras $ [ line $ "Binder list length differs in case alternative:"
947+ paras [ line "Binder list length differs in case alternative:"
919− , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
948+ , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
920− , line $ "Expecting " ++ show l ++ " binder" ++ (if l == 1 then "" else "s") ++ "." ]
949+ , line $ "Expecting " ++ show l ++ " binder" ++ (if l == 1 then "" else "s") ++ "."
952+ renderSimpleErrorMessage IncorrectAnonymousArgument =
953+ line "An anonymous function argument appears in an invalid context."
922 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
955 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
923 renderHint (ErrorUnifyingTypes t1 t2) detail =
956 renderHint (ErrorUnifyingTypes t1 t2) detail =