@@ -24,6 +24,7 @@ import Control.Arrow ((&&&))
2424import Language.PureScript.Crash
2525import Language.PureScript.AST
2626import Language.PureScript.Pretty
27+import Language.PureScript.Pretty.Common (before)
2728import Language.PureScript.Types
2829import Language.PureScript.Names
2930import Language.PureScript.Kinds
@@ -128,6 +129,7 @@ data SimpleErrorMessage
128129 | UnusedDctorImport (ProperName 'TypeName)
129130 | UnusedDctorExplicitImport (ProperName 'TypeName) [ProperName 'ConstructorName]
130131 | DeprecatedOperatorDecl String
132+ | DeprecatedOperatorSection Expr (Either Expr Expr)
131133 | DeprecatedQualifiedSyntax ModuleName ModuleName
132134 | DeprecatedClassImport ModuleName (ProperName 'ClassName)
133135 | DeprecatedClassExport (ProperName 'ClassName)
@@ -142,6 +144,7 @@ data SimpleErrorMessage
142144 | ImplicitImport ModuleName [DeclarationRef]
143145 | HidingImport ModuleName [DeclarationRef]
144146 | CaseBinderLengthDiffers Int [Binder]
147+ | IncorrectAnonymousArgument
145148 deriving (Show)
146149
147150-- | Error message hints, providing more detailed information about failure.
@@ -303,6 +306,7 @@ errorCode em = case unwrapErrorMessage em of
303306 UnusedDctorImport{} -> "UnusedDctorImport"
304307 UnusedDctorExplicitImport{} -> "UnusedDctorExplicitImport"
305308 DeprecatedOperatorDecl{} -> "DeprecatedOperatorDecl"
309+ DeprecatedOperatorSection{} -> "DeprecatedOperatorSection"
306310 DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
307311 DeprecatedClassImport{} -> "DeprecatedClassImport"
308312 DeprecatedClassExport{} -> "DeprecatedClassExport"
@@ -317,6 +321,7 @@ errorCode em = case unwrapErrorMessage em of
317321 ImplicitImport{} -> "ImplicitImport"
318322 HidingImport{} -> "HidingImport"
319323 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
324+ IncorrectAnonymousArgument -> "IncorrectAnonymousArgument"
320325
321326-- |
322327-- A stack trace for an error
@@ -424,7 +429,7 @@ wikiUri e = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ error
424429-- TODO Other possible suggestions:
425430-- WildcardInferredType - source span not small enough
426431-- 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?
428433errorSuggestion :: SimpleErrorMessage -> Maybe ErrorSuggestion
429434errorSuggestion err = case err of
430435 UnusedImport{} -> emptySuggestion
@@ -798,7 +803,7 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
798803 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
799804 line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors."
800805 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."
802807 , line $ "An attempt was made to hide the import of " ++ runModuleName name
803808 ]
804809 renderSimpleErrorMessage (WildcardInferredType ty) =
@@ -812,14 +817,14 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
812817 , indent $ typeAsBox ty
813818 ]
814819 renderSimpleErrorMessage (NotExhaustivePattern bs b) =
815− 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"
817− , indent $ paras $
818− [ Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs)) ]
819− ++ [ line "..." | not b ]
820− , 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."
822− ]
820+ paras [ line "A case expression could not be determined to cover all inputs."
821+ , line "The following additional cases are required to cover all inputs:\n"
822+ , indent $ paras $
823+ [ Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs)) ]
824+ ++ [ line "..." | not b ]
825+ , line "Or alternatively, add a Partial constraint to the type of the enclosing value."
826+ , line "Non-exhaustive patterns for values without a `Partial` constraint will be disallowed in PureScript 0.9."
827+ ]
823828 renderSimpleErrorMessage (OverlappingPattern bs b) =
824829 paras $ [ line "A case expression contains unreachable cases:\n"
825830 , Box.hsep 1 Box.left (map (paras . map (line . prettyPrintBinderAtom)) (transpose bs))
@@ -835,7 +840,7 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
835840 renderSimpleErrorMessage msg@(UnusedExplicitImport mn names _ _) =
836841 paras [ line $ "The import of module " ++ runModuleName mn ++ " contains the following unused references:"
837842 , indent $ paras $ map line names
838− , line $ "It could be replaced with:"
843+ , line "It could be replaced with:"
839844 , indent $ line $ showSuggestion msg ]
840845
841846 renderSimpleErrorMessage (UnusedDctorImport name) =
@@ -849,15 +854,39 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
849854 paras [ line $ "The operator (" ++ name ++ ") was declared as a value rather than an alias for a named function."
850855 , line "Operator aliases are declared by using a fixity declaration, for example:"
851856 , 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."
853858 ]
854859
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 $
863+ case val of
864+ Left l ->
865+ [ line "("
866+ , prettyPrintValue valueDepth l
867+ , line " "
868+ , renderOperator op
869+ , line " _)"
870+ ]
871+ Right r ->
872+ [ line "(_ "
873+ , renderOperator op
874+ , line " "
875+ , prettyPrintValue valueDepth r
876+ , line ")"
877+ ]
878+ , line "Support for legacy operator sections will be removed in PureScript 0.9."
879+ ]
880+ where
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 "`" ]
855884 renderSimpleErrorMessage (DeprecatedQualifiedSyntax name qualName) =
856− paras [ line $ "Import uses the deprecated 'qualified' syntax:"
885+ paras [ line "Import uses the deprecated 'qualified' syntax:"
857886 , indent $ line $ "import qualified " ++ runModuleName name ++ " as " ++ runModuleName qualName
858887 , line "Should instead use the form:"
859888 , 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."
861890 ]
862891
863892 renderSimpleErrorMessage (DeprecatedClassImport mn name) =
@@ -865,15 +894,15 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
865894 , indent $ line $ runProperName name
866895 , line "Should instead use the form:"
867896 , 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."
869898 ]
870899
871900 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:"
873902 , indent $ line $ runProperName name
874903 , line "Should instead use the form:"
875904 , 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."
877906 ]
878907
879908 renderSimpleErrorMessage (RedundantUnqualifiedImport name imp) =
@@ -915,9 +944,13 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
915944 ]
916945
917946 renderSimpleErrorMessage (CaseBinderLengthDiffers l bs) =
918− paras $ [ line $ "Binder list length differs in case alternative:"
919− , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
920− , line $ "Expecting " ++ show l ++ " binder" ++ (if l == 1 then "" else "s") ++ "." ]
947+ paras [ line "Binder list length differs in case alternative:"
948+ , indent $ line $ intercalate ", " $ fmap prettyPrintBinderAtom bs
949+ , line $ "Expecting " ++ show l ++ " binder" ++ (if l == 1 then "" else "s") ++ "."
950+ ]
951+
952+ renderSimpleErrorMessage IncorrectAnonymousArgument =
953+ line "An anonymous function argument appears in an invalid context."
921954
922955 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
923956 renderHint (ErrorUnifyingTypes t1 t2) detail =