@@ -20,7 +20,7 @@
2020module Language.PureScript.Errors where
2121
2222import Data.Either (lefts, rights)
23−import Data.List (intercalate, transpose, nub, nubBy, partition)
23+import Data.List (intercalate, transpose, nub, nubBy)
2424import Data.Function (on)
2525#if __GLASGOW_HASKELL__ < 710
2626import Data.Foldable (fold, foldMap)
@@ -41,8 +41,8 @@ import Control.Applicative ((<$>), (<*>), Applicative, pure)
4141import Control.Monad.Trans.State.Lazy
4242import Control.Arrow(first)
4343
44+import Language.PureScript.Crash
4445import Language.PureScript.AST
45−import Language.PureScript.Environment (isObject, isFunction)
4646import Language.PureScript.Pretty
4747import Language.PureScript.Types
4848import Language.PureScript.Names
@@ -56,19 +56,16 @@ import Text.Parsec.Error (Message(..))
5656
5757-- | A type of error messages
5858data SimpleErrorMessage
59− = ErrorParsingExterns P.ParseError
60− | ErrorParsingFFIModule FilePath
59+ = ErrorParsingFFIModule FilePath
6160 | ErrorParsingModule P.ParseError
6261 | MissingFFIModule ModuleName
6362 | MultipleFFIModules ModuleName [FilePath]
6463 | UnnecessaryFFIModule ModuleName FilePath
65− | InvalidExternsFile FilePath
6664 | CannotGetFileInfo FilePath
6765 | CannotReadFile FilePath
6866 | CannotWriteFile FilePath
6967 | InfiniteType Type
7068 | InfiniteKind Kind
71− | CannotReorderOperators
7269 | MultipleFixities Ident
7370 | OrphanTypeDeclaration Ident
7471 | OrphanFixityDeclaration String
@@ -108,11 +105,9 @@ data SimpleErrorMessage
108105 | CycleInTypeSynonym (Maybe ProperName)
109106 | CycleInModules [ModuleName]
110107 | NameIsUndefined Ident
111− | NameNotInScope Ident
112108 | UndefinedTypeVariable ProperName
113109 | PartiallyAppliedSynonym (Qualified ProperName)
114110 | EscapedSkolem (Maybe Expr)
115− | UnspecifiedSkolemScope
116111 | TypesDoNotUnify Type Type
117112 | KindsDoNotUnify Kind Kind
118113 | ConstrainedTypeUnified Type Type
@@ -126,23 +121,23 @@ data SimpleErrorMessage
126121 | ArgListLengthsDiffer Ident
127122 | OverlappingArgNames (Maybe Ident)
128123 | MissingClassMember Ident
129− | ExtraneousClassMember Ident
124+ | ExtraneousClassMember Ident (Qualified ProperName)
130125 | ExpectedType Type Kind
131126 | IncorrectConstructorArity (Qualified ProperName)
132− | SubsumptionCheckFailed
133127 | ExprDoesNotHaveType Expr Type
134− | PropertyIsMissing String Type
128+ | PropertyIsMissing String
129+ | AdditionalProperty String
135130 | CannotApplyFunction Type Expr
136131 | TypeSynonymInstance
137132 | OrphanInstance Ident (Qualified ProperName) [Type]
138− | InvalidNewtype
133+ | InvalidNewtype ProperName
139134 | InvalidInstanceHead Type
140135 | TransitiveExportError DeclarationRef [DeclarationRef]
141136 | ShadowedName Ident
142137 | ShadowedTypeVar String
143138 | UnusedTypeVar String
144139 | WildcardInferredType Type
145− | MissingTypeDeclaration Ident
140+ | MissingTypeDeclaration Ident Type
146141 | NotExhaustivePattern [[Binder]] Bool
147142 | OverlappingPattern [[Binder]] Bool
148143 | IncompleteExhaustivityCheck
@@ -153,14 +148,15 @@ data SimpleErrorMessage
153148
154149-- | Error message hints, providing more detailed information about failure.
155150data ErrorMessageHint
156− = NotYetDefined [Ident]
157− | ErrorUnifyingTypes Type Type
151+ = ErrorUnifyingTypes Type Type
158152 | ErrorInExpression Expr
159153 | ErrorInModule ModuleName
160154 | ErrorInInstance (Qualified ProperName) [Type]
161155 | ErrorInSubsumption Type Type
156+ | ErrorCheckingAccessor Expr String
162157 | ErrorCheckingType Expr Type
163158 | ErrorCheckingKind Type
159+ | ErrorCheckingGuard
164160 | ErrorInferringType Expr
165161 | ErrorInApplication Expr Type Expr
166162 | ErrorInDataConstructor ProperName
@@ -196,19 +192,16 @@ instance UnificationError Kind ErrorMessage where
196192--
197193errorCode :: ErrorMessage -> String
198194errorCode em = case unwrapErrorMessage em of
199− ErrorParsingExterns{} -> "ErrorParsingExterns"
200195 ErrorParsingFFIModule{} -> "ErrorParsingFFIModule"
201196 ErrorParsingModule{} -> "ErrorParsingModule"
202197 MissingFFIModule{} -> "MissingFFIModule"
203198 MultipleFFIModules{} -> "MultipleFFIModules"
204199 UnnecessaryFFIModule{} -> "UnnecessaryFFIModule"
205− InvalidExternsFile{} -> "InvalidExternsFile"
206200 CannotGetFileInfo{} -> "CannotGetFileInfo"
207201 CannotReadFile{} -> "CannotReadFile"
208202 CannotWriteFile{} -> "CannotWriteFile"
209203 InfiniteType{} -> "InfiniteType"
210204 InfiniteKind{} -> "InfiniteKind"
211− CannotReorderOperators -> "CannotReorderOperators"
212205 MultipleFixities{} -> "MultipleFixities"
213206 OrphanTypeDeclaration{} -> "OrphanTypeDeclaration"
214207 OrphanFixityDeclaration{} -> "OrphanFixityDeclaration"
@@ -248,11 +241,9 @@ errorCode em = case unwrapErrorMessage em of
248241 CycleInTypeSynonym{} -> "CycleInTypeSynonym"
249242 CycleInModules{} -> "CycleInModules"
250243 NameIsUndefined{} -> "NameIsUndefined"
251− NameNotInScope{} -> "NameNotInScope"
252244 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
253245 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
254246 EscapedSkolem{} -> "EscapedSkolem"
255− UnspecifiedSkolemScope -> "UnspecifiedSkolemScope"
256247 TypesDoNotUnify{} -> "TypesDoNotUnify"
257248 KindsDoNotUnify{} -> "KindsDoNotUnify"
258249 ConstrainedTypeUnified{} -> "ConstrainedTypeUnified"
@@ -269,13 +260,13 @@ errorCode em = case unwrapErrorMessage em of
269260 ExtraneousClassMember{} -> "ExtraneousClassMember"
270261 ExpectedType{} -> "ExpectedType"
271262 IncorrectConstructorArity{} -> "IncorrectConstructorArity"
272− SubsumptionCheckFailed -> "SubsumptionCheckFailed"
273263 ExprDoesNotHaveType{} -> "ExprDoesNotHaveType"
274264 PropertyIsMissing{} -> "PropertyIsMissing"
265+ AdditionalProperty{} -> "AdditionalProperty"
275266 CannotApplyFunction{} -> "CannotApplyFunction"
276267 TypeSynonymInstance -> "TypeSynonymInstance"
277268 OrphanInstance{} -> "OrphanInstance"
278− InvalidNewtype -> "InvalidNewtype"
269+ InvalidNewtype{} -> "InvalidNewtype"
279270 InvalidInstanceHead{} -> "InvalidInstanceHead"
280271 TransitiveExportError{} -> "TransitiveExportError"
281272 ShadowedName{} -> "ShadowedName"
@@ -362,7 +353,6 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
362353 gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
363354 gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> f t1 <*> f t2
364355 gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> f t
365− gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> f t
366356 gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
367357 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
368358 gSimple other = pure other
@@ -377,17 +367,18 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
377367-- Pretty print a single error, simplifying if necessary
378368--
379369prettyPrintSingleError :: Bool -> Level -> ErrorMessage -> State UnknownMap Box.Box
380−prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFirst . reverseHints <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
381− where
370+prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
371+ where
382372
383373 -- Pretty print an ErrorMessage
384374 prettyPrintErrorMessage :: ErrorMessage -> Box.Box
385375 prettyPrintErrorMessage (ErrorMessage hints simple) =
386376 paras $
387− map renderHint hints ++
388− renderSimpleErrorMessage simple :
389− suggestions simple ++
390− [line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."]
377+ [ foldr renderHint (indent (renderSimpleErrorMessage simple)) hints
378+ , Box.moveDown 1 $ paras [ line $ "See " ++ wikiUri ++ " for more information, "
379+ , line $ "or to contribute content related to this " ++ levelText ++ "."
380+ ]
381+ ]
391382 where
392383 wikiUri :: String
393384 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
@@ -405,12 +396,8 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
405396 paras [ line "Unable to write file: "
406397 , indent . line $ path
407398 ]
408− renderSimpleErrorMessage (ErrorParsingExterns err) =
409− paras [ lineWithLevel "parsing externs files: "
410− , prettyPrintParseError err
411− ]
412399 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
413− paras [ line "Unable to parse module from FFI file: "
400+ paras [ line "Unable to parse foreign module:"
414401 , indent . line $ path
415402 ]
416403 renderSimpleErrorMessage (ErrorParsingModule err) =
@@ -418,29 +405,22 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
418405 , prettyPrintParseError err
419406 ]
420407 renderSimpleErrorMessage (MissingFFIModule mn) =
421− line $ "Missing FFI implementations for module " ++ runModuleName mn
408+ line $ "The foreign module implementation for module " ++ runModuleName mn ++ " is missing."
422409 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
423− paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
410+ paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ runModuleName mn ++ ": "
424411 , indent . line $ path
412+ , line $ "Module " ++ runModuleName mn ++ " does not contain any foreign import declarations, so a foreign module is not necessary."
425413 ]
426414 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
427− paras [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
415+ paras [ line $ "Multiple foreign module implementations have been provided for module " ++ runModuleName mn ++ ": "
428416 , indent . paras $ map line paths
429417 ]
430− renderSimpleErrorMessage (InvalidExternsFile path) =
431− paras [ line "Externs file is invalid: "
432− , indent . line $ path
433− ]
434418 renderSimpleErrorMessage InvalidDoBind =
435− line "Bind statement cannot be the last statement in a do block. The last statement must be an expression."
419+ line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
436420 renderSimpleErrorMessage InvalidDoLet =
437− line "Let statement cannot be the last statement in a do block. The last statement must be an expression."
438− renderSimpleErrorMessage CannotReorderOperators =
439− line "Unable to reorder operators"
440− renderSimpleErrorMessage UnspecifiedSkolemScope =
441− line "Skolem variable scope is unspecified"
421+ line "The last statement in a 'do' block must be an expression, but this block ends with a let binding."
442422 renderSimpleErrorMessage OverlappingNamesInLet =
443− line "Overlapping names in let binding."
423+ line "The same name was used more than once in a let binding."
444424 renderSimpleErrorMessage (InfiniteType ty) =
445425 paras [ line "An infinite type was inferred for an expression: "
446426 , indent $ typeAsBox ty
@@ -450,17 +430,17 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
450430 , indent $ line $ prettyPrintKind ki
451431 ]
452432 renderSimpleErrorMessage (MultipleFixities name) =
453− line $ "Multiple fixity declarations for " ++ showIdent name
433+ line $ "There are multiple fixity/precedence declarations for " ++ showIdent name
454434 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
455− line $ "Orphan type declaration for " ++ showIdent nm
435+ line $ "The type declaration for " ++ showIdent nm ++ " should be followed by its definition."
456436 renderSimpleErrorMessage (OrphanFixityDeclaration op) =
457− line $ "Orphan fixity declaration for " ++ show op
437+ line $ "The fixity/precedence declaration for " ++ show op ++ " should appear in the same module as its definition."
458438 renderSimpleErrorMessage (RedefinedModule name filenames) =
459− paras [ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
439+ paras [ line ("The module " ++ runModuleName name ++ " has been defined multiple times:")
460440 , indent . paras $ map (line . displaySourceSpan) filenames
461441 ]
462442 renderSimpleErrorMessage (RedefinedIdent name) =
463− line $ "Name " ++ showIdent name ++ " has been defined multiple times"
443+ line $ "The value " ++ showIdent name ++ " has been defined multiple times"
464444 renderSimpleErrorMessage (UnknownModule mn) =
465445 line $ "Unknown module " ++ runModuleName mn
466446 renderSimpleErrorMessage (UnknownType name) =
@@ -474,25 +454,36 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
474454 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
475455 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
476456 renderSimpleErrorMessage (UnknownImportType mn name) =
477− line $ "Module " ++ runModuleName mn ++ " does not export type " ++ runProperName name
457+ paras [ line $ "Cannot import type " ++ runProperName name ++ " from module " ++ runModuleName mn
458+ , line "It either does not exist or the module does not export it."
459+ ]
478460 renderSimpleErrorMessage (UnknownExportType name) =
479461 line $ "Cannot export unknown type " ++ runProperName name
480462 renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
481− line $ "Module " ++ runModuleName mn ++ " does not export type class " ++ runProperName name
463+ paras [ line $ "Cannot import type class " ++ runProperName name ++ " from module " ++ runModuleName mn
464+ , line "It either does not exist or the module does not export it."
465+ ]
482466 renderSimpleErrorMessage (UnknownExportTypeClass name) =
483467 line $ "Cannot export unknown type class " ++ runProperName name
484468 renderSimpleErrorMessage (UnknownImportValue mn name) =
485− line $ "Module " ++ runModuleName mn ++ " does not export value " ++ showIdent name
469+ paras [ line $ "Cannot import value " ++ showIdent name ++ " from module " ++ runModuleName mn
470+ , line "It either does not exist or the module does not export it."
471+ ]
486472 renderSimpleErrorMessage (UnknownExportValue name) =
487473 line $ "Cannot export unknown value " ++ showIdent name
488474 renderSimpleErrorMessage (UnknownExportModule name) =
489− line $ "Cannot export unknown module " ++ runModuleName name ++ ", it either does not exist or has not been imported by the current module"
475+ paras [ line $ "Cannot export unknown module " ++ runModuleName name
476+ , line "It either does not exist or has not been imported by the current module."
477+ ]
490478 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
491479 line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
492480 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
493− line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ " as it has not been declared"
481+ line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ ", as it has not been declared."
494482 renderSimpleErrorMessage (ConflictingImport nm mn) =
495− line $ "Cannot declare " ++ show nm ++ " since another declaration of that name was imported from " ++ runModuleName mn
483+ paras [ line $ "Cannot declare " ++ show nm ++ ", since another declaration of that name was imported from module " ++ runModuleName mn
484+ , line $ "Consider hiding " ++ show nm ++ " when importing " ++ runModuleName mn ++ ":"
485+ , indent . line $ "import " ++ runModuleName mn ++ " hiding (" ++ nm ++ ")"
486+ ]
496487 renderSimpleErrorMessage (ConflictingImports nm m1 m2) =
497488 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
498489 renderSimpleErrorMessage (ConflictingTypeDecls nm) =
@@ -500,13 +491,13 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
500491 renderSimpleErrorMessage (ConflictingCtorDecls nm) =
501492 line $ "Conflicting data constructor declarations for " ++ runProperName nm
502493 renderSimpleErrorMessage (TypeConflictsWithClass nm) =
503− line $ "Type " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
494+ line $ "Type " ++ runProperName nm ++ " conflicts with a type class declaration with the same name."
504495 renderSimpleErrorMessage (CtorConflictsWithClass nm) =
505− line $ "Data constructor " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
496+ line $ "Data constructor " ++ runProperName nm ++ " conflicts with a type class declaration with the same name."
506497 renderSimpleErrorMessage (ClassConflictsWithType nm) =
507− line $ "Type class " ++ runProperName nm ++ " conflicts with type declaration of the same name"
498+ line $ "Type class " ++ runProperName nm ++ " conflicts with a type declaration with the same name."
508499 renderSimpleErrorMessage (ClassConflictsWithCtor nm) =
509− line $ "Type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name"
500+ line $ "Type class " ++ runProperName nm ++ " conflicts with a data constructor declaration with the same name."
510501 renderSimpleErrorMessage (DuplicateModuleName mn) =
511502 line $ "Module " ++ runModuleName mn ++ " has been defined multiple times."
512503 renderSimpleErrorMessage (DuplicateClassExport nm) =
@@ -514,19 +505,24 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
514505 renderSimpleErrorMessage (DuplicateValueExport nm) =
515506 line $ "Duplicate export declaration for value " ++ showIdent nm
516507 renderSimpleErrorMessage (CycleInDeclaration nm) =
517− line $ "Cycle in declaration of " ++ showIdent nm
508+ line $ "The value of " ++ showIdent nm ++ " is undefined here, so this reference is not allowed."
518509 renderSimpleErrorMessage (CycleInModules mns) =
519− line $ "Cycle in module dependencies: " ++ intercalate ", " (map runModuleName mns)
520− renderSimpleErrorMessage (CycleInTypeSynonym pn) =
521− line $ "Cycle in type synonym" ++ foldMap ((" " ++) . runProperName) pn
510+ paras [ line $ "There is a cycle in module dependencies in these modules: "
511+ , indent $ paras (map (line . runModuleName) mns)
512+ ]
513+ renderSimpleErrorMessage (CycleInTypeSynonym name) =
514+ paras [ line $ case name of
515+ Just pn -> "A cycle appears in the definition of type synonym " ++ runProperName pn
516+ Nothing -> "A cycle appears in a set of type synonym definitions."
517+ , line "Cycles are disallowed because they can lead to loops in the type checker."
518+ , line "Consider using a 'newtype' instead."
519+ ]
522520 renderSimpleErrorMessage (NameIsUndefined ident) =
523− line $ showIdent ident ++ " is undefined"
524− renderSimpleErrorMessage (NameNotInScope ident) =
525− line $ showIdent ident ++ " may not be defined in the current scope"
521+ line $ "Value " ++ showIdent ident ++ " is undefined."
526522 renderSimpleErrorMessage (UndefinedTypeVariable name) =
527− line $ "Type variable " ++ runProperName name ++ " is undefined"
523+ line $ "Type variable " ++ runProperName name ++ " is undefined."
528524 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
529− paras [ line $ "Partially applied type synonym " ++ showQualified runProperName name
525+ paras [ line $ "Type synonym " ++ showQualified runProperName name ++ " is partially applied."
530526 , line "Type synonyms must be applied to all of their type arguments."
531527 ]
532528 renderSimpleErrorMessage (EscapedSkolem binding) =
@@ -535,70 +531,72 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
535531 , indent $ prettyPrintValue expr
536532 ]) binding
537533 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
538− = paras [ line "Cannot unify type"
534+ = paras [ line "Could not match type"
539535 , indent $ typeAsBox t1
540536 , line "with type"
541537 , indent $ typeAsBox t2
542538 ]
543539 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
544− paras [ line "Cannot unify kind"
540+ paras [ line "Could not match kind"
545541 , indent $ line $ prettyPrintKind k1
546542 , line "with kind"
547543 , indent $ line $ prettyPrintKind k2
548544 ]
549545 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
550− paras [ line "Cannot unify constrained type"
546+ paras [ line "Could not match constrained type"
551547 , indent $ typeAsBox t1
552548 , line "with type"
553549 , indent $ typeAsBox t2
554550 ]
555551 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
556− paras [ line "Overlapping instances found for"
552+ paras [ line "Overlapping type class instances found for"
557553 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
558554 , Box.vcat Box.left (map typeAtomAsBox ts)
559555 ]
560556 , line "The following instances were found:"
561557 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
558+ , line "Overlapping type class instances can lead to different behavior based on the order of module imports, and for that reason are not recommended."
559+ , line "They may be disallowed completely in a future version of the compiler."
562560 ]
563− renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
561+ renderSimpleErrorMessage OverlappingInstances{} = internalError "OverlappingInstances: empty instance list"
564562 renderSimpleErrorMessage (NoInstanceFound nm ts) =
565− paras [ line "No instance found for"
563+ paras [ line "No type class instance was found for"
566564 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
567565 , Box.vcat Box.left (map typeAtomAsBox ts)
568566 ]
569567 ]
570568 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
571− paras [ line "Instance for"
569+ paras [ line "Type class instance for"
572570 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
573571 , Box.vcat Box.left (map typeAtomAsBox ts)
574572 ]
575573 , line "is possibly infinite."
576574 ]
577575 renderSimpleErrorMessage (CannotDerive nm ts) =
578− paras [ line "Cannot derive an instance for"
576+ paras [ line "Cannot derive a type class instance for"
579577 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
580578 , Box.vcat Box.left (map typeAtomAsBox ts)
581579 ]
582580 ]
583581 renderSimpleErrorMessage (CannotFindDerivingType nm) =
584− line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
582+ line $ "Cannot derive a type class instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
585583 renderSimpleErrorMessage (DuplicateLabel l expr) =
586− paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
584+ paras $ [ line $ "Label " ++ show l ++ " appears more than once in a row type." ]
587585 <> foldMap (\expr' -> [ line "Relevant expression: "
588586 , indent $ prettyPrintValue expr'
589587 ]) expr
590588 renderSimpleErrorMessage (DuplicateTypeArgument name) =
591− line $ "Duplicate type argument " ++ show name
589+ line $ "Type argument " ++ show name ++ " appears more than once."
592590 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
593− line $ "Duplicate value declaration for " ++ showIdent nm
591+ line $ "Multiple value declarations exist for " ++ showIdent nm ++ "."
594592 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
595593 line $ "Argument list lengths differ in declaration " ++ showIdent ident
596594 renderSimpleErrorMessage (OverlappingArgNames ident) =
597595 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
598596 renderSimpleErrorMessage (MissingClassMember ident) =
599− line $ "Member " ++ showIdent ident ++ " has not been implemented"
600− renderSimpleErrorMessage (ExtraneousClassMember ident) =
601− line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
597+ line $ "Type class member " ++ showIdent ident ++ " has not been implemented."
598+ renderSimpleErrorMessage (ExtraneousClassMember ident className) =
599+ line $ showIdent ident ++ " is not a member of type class " ++ showQualified runProperName className
602600 renderSimpleErrorMessage (ExpectedType ty kind) =
603601 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
604602 , line "The error arises from the type"
@@ -608,29 +606,27 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
608606 , line "instead."
609607 ]
610608 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
611− line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
612− renderSimpleErrorMessage SubsumptionCheckFailed = line "Unable to check type subsumption"
609+ line $ "Data constructor " ++ showQualified runProperName nm ++ " was given the wrong number of arguments in a case expression."
613610 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
614611 paras [ line "Expression"
615612 , indent $ prettyPrintValue expr
616613 , line "does not have type"
617614 , indent $ typeAsBox ty
618615 ]
619− renderSimpleErrorMessage (PropertyIsMissing prop row) =
620− paras [ line "Row"
621− , indent $ prettyPrintRowWith '(' ')' row
622− , line $ "lacks required property " ++ show prop
623− ]
616+ renderSimpleErrorMessage (PropertyIsMissing prop) =
617+ line $ "Type of expression lacks required label " ++ show prop ++ "."
618+ renderSimpleErrorMessage (AdditionalProperty prop) =
619+ line $ "Type of expression contains additional label " ++ show prop ++ "."
624620 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
625− paras [ line "Cannot apply function of type"
621+ paras [ line "A function of type"
626622 , indent $ typeAsBox fn
627− , line "to argument"
623+ , line "can not be applied to the argument"
628624 , indent $ prettyPrintValue arg
629625 ]
630626 renderSimpleErrorMessage TypeSynonymInstance =
631− line "Type synonym instances are disallowed"
627+ line "Type class instances for type synonyms are disallowed."
632628 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
633− paras [ line $ "Instance " ++ showIdent nm ++ " for "
629+ paras [ line $ "Type class instance " ++ showIdent nm ++ " for "
634630 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
635631 , Box.vcat Box.left (map typeAtomAsBox ts)
636632 ]
@@ -638,39 +634,44 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
638634 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
639635 , line "Consider moving the instance, if possible, or using a newtype wrapper."
640636 ]
641− renderSimpleErrorMessage InvalidNewtype =
642− line "Newtypes must define a single constructor with a single argument"
637+ renderSimpleErrorMessage (InvalidNewtype name) =
638+ paras [ line $ "Newtype " ++ runProperName name ++ " is invalid."
639+ , line "Newtypes must define a single constructor with a single argument."
640+ ]
643641 renderSimpleErrorMessage (InvalidInstanceHead ty) =
644− paras [ line "Invalid type in class instance head:"
642+ paras [ line "Type class instance head is invalid due to use of type"
645643 , indent $ typeAsBox ty
644+ , line "All types appearing in instance declarations must be of the form T a_1 .. a_n, where each type a_i is of the same form."
646645 ]
647646 renderSimpleErrorMessage (TransitiveExportError x ys) =
648647 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
649648 : map (line . prettyPrintExport) ys
650649 renderSimpleErrorMessage (ShadowedName nm) =
651− line $ "Name '" ++ showIdent nm ++ "' was shadowed"
650+ line $ "Name '" ++ showIdent nm ++ "' was shadowed."
652651 renderSimpleErrorMessage (ShadowedTypeVar tv) =
653− line $ "Type variable '" ++ tv ++ "' was shadowed"
652+ line $ "Type variable '" ++ tv ++ "' was shadowed."
654653 renderSimpleErrorMessage (UnusedTypeVar tv) =
655− line $ "Type variable '" ++ tv ++ "' was declared but not used"
654+ line $ "Type variable '" ++ tv ++ "' was declared but not used."
656655 renderSimpleErrorMessage (ClassOperator className opName) =
657− paras [ line $ "Class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
656+ paras [ line $ "Type class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
658657 , line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
659658 , indent . line $ showIdent opName ++ " = someMember"
660659 ]
661660 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
662− line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors"
661+ line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors."
663662 renderSimpleErrorMessage (ImportHidingModule name) =
664− line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
663+ paras [ line $ "'hiding' imports cannot be used to hide modules."
664+ , line $ "An attempt was made to hide the import of " ++ runModuleName name
665+ ]
665666 renderSimpleErrorMessage (WildcardInferredType ty) =
666− paras [ line "The wildcard type definition has the inferred type "
667+ paras [ line "Wildcard type definition has the inferred type "
667668 , indent $ typeAsBox ty
668669 ]
669− renderSimpleErrorMessage (MissingTypeDeclaration ident) =
670+ renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
670671 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
671672 , line "It is good practice to provide type declarations as a form of documentation."
672− , line "Consider using a type wildcard to display the inferred type:"
673− , indent $ line $ showIdent ident ++ " :: _"
673+ , line $ "The inferred type of " ++ showIdent ident ++ " was:"
674+ , indent $ typeAsBox ty
674675 ]
675676 renderSimpleErrorMessage (NotExhaustivePattern bs b) =
676677 paras $ [ line "A case expression could not be determined to cover all inputs."
@@ -685,95 +686,130 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
685686 [ line "..." | not b ]
686687 renderSimpleErrorMessage IncompleteExhaustivityCheck =
687688 paras [ line "An exhaustivity check was abandoned due to too many possible cases."
688− , line "You may want to decomposing your data types into smaller types."
689− ]
690−
691− renderHint :: ErrorMessageHint -> Box.Box
692− renderHint (NotYetDefined names) =
693− line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
694− renderHint (ErrorUnifyingTypes t1 t2) =
695− paras [ lineWithLevel "unifying type "
696− , indent $ typeAsBox t1
697− , line "with type"
698− , indent $ typeAsBox t2
689+ , line "You may want to decompose your data types into smaller types."
690+ ]
691+
692+ renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
693+ renderHint (ErrorUnifyingTypes t1 t2) detail =
694+ paras [ detail
695+ , Box.hsep 1 Box.top [ line "while trying to match type"
696+ , typeAsBox t1
697+ ]
698+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "with type"
699+ , typeAsBox t2
700+ ]
701+ ]
702+ renderHint (ErrorInExpression expr) detail =
703+ paras [ detail
704+ , Box.hsep 1 Box.top [ Box.text "in the expression"
705+ , prettyPrintValue expr
706+ ]
707+ ]
708+ renderHint (ErrorInModule mn) detail =
709+ paras [ line $ "in module " ++ runModuleName mn
710+ , detail
711+ ]
712+ renderHint (ErrorInSubsumption t1 t2) detail =
713+ paras [ detail
714+ , Box.hsep 1 Box.top [ line "while checking that type"
715+ , typeAsBox t1
716+ ]
717+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "is at least as general as type"
718+ , typeAsBox t2
719+ ]
720+ ]
721+ renderHint (ErrorInInstance nm ts) detail =
722+ paras [ detail
723+ , Box.hsep 1 Box.top [ line "in type class instance"
724+ , line (showQualified runProperName nm)
725+ , Box.vcat Box.left (map typeAtomAsBox ts)
726+ ]
727+ ]
728+ renderHint (ErrorCheckingKind ty) detail =
729+ paras [ detail
730+ , Box.hsep 1 Box.top [ line "while checking the kind of"
731+ , typeAsBox ty
732+ ]
733+ ]
734+ renderHint ErrorCheckingGuard detail =
735+ paras [ detail
736+ , line "while checking the type of a guard clause"
737+ ]
738+ renderHint (ErrorInferringType expr) detail =
739+ paras [ detail
740+ , Box.hsep 1 Box.top [ line "while inferring the type of"
741+ , prettyPrintValue expr
742+ ]
743+ ]
744+ renderHint (ErrorCheckingType expr ty) detail =
745+ paras [ detail
746+ , Box.hsep 1 Box.top [ line "while checking that expression"
747+ , prettyPrintValue expr
748+ ]
749+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "has type"
750+ , typeAsBox ty
751+ ]
752+ ]
753+ renderHint (ErrorCheckingAccessor expr prop) detail =
754+ paras [ detail
755+ , Box.hsep 1 Box.top [ line "while checking type of property accessor"
756+ , prettyPrintValue (Accessor prop expr)
757+ ]
758+ ]
759+ renderHint (ErrorInApplication f t a) detail =
760+ paras [ detail
761+ , Box.hsep 1 Box.top [ line "while applying a function"
762+ , prettyPrintValue f
763+ ]
764+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "of type"
765+ , typeAsBox t
766+ ]
767+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "to argument"
768+ , prettyPrintValue a
769+ ]
770+ ]
771+ renderHint (ErrorInDataConstructor nm) detail =
772+ paras [ detail
773+ , line $ "in data constructor " ++ runProperName nm
774+ ]
775+ renderHint (ErrorInTypeConstructor nm) detail =
776+ paras [ detail
777+ , line $ "in type constructor " ++ runProperName nm
778+ ]
779+ renderHint (ErrorInBindingGroup nms) detail =
780+ paras [ detail
781+ , line $ "in binding group " ++ intercalate ", " (map showIdent nms)
782+ ]
783+ renderHint ErrorInDataBindingGroup detail =
784+ paras [ detail
785+ , line "in data binding group"
786+ ]
787+ renderHint (ErrorInTypeSynonym name) detail =
788+ paras [ detail
789+ , line $ "in type synonym " ++ runProperName name
790+ ]
791+ renderHint (ErrorInValueDeclaration n) detail =
792+ paras [ detail
793+ , line $ "in value declaration " ++ showIdent n
794+ ]
795+ renderHint (ErrorInTypeDeclaration n) detail =
796+ paras [ detail
797+ , line $ "in type declaration for " ++ showIdent n
798+ ]
799+ renderHint (ErrorInForeignImport nm) detail =
800+ paras [ detail
801+ , line $ "in foreign import " ++ showIdent nm
802+ ]
803+ renderHint (PositionedError srcSpan) detail =
804+ paras [ line $ "at " ++ displaySourceSpan srcSpan
805+ , detail
699806 ]
700− renderHint (ErrorInExpression expr) =
701− paras [ lineWithLevel "in expression:"
702− , indent $ prettyPrintValue expr
703− ]
704− renderHint (ErrorInModule mn) =
705− paras [ lineWithLevel $ "in module " ++ runModuleName mn ++ ":"
706− ]
707− renderHint (ErrorInSubsumption t1 t2) =
708− paras [ lineWithLevel "checking that type "
709− , indent $ typeAsBox t1
710− , line "subsumes type"
711− , indent $ typeAsBox t2
712− ]
713− renderHint (ErrorInInstance nm ts) =
714− paras [ lineWithLevel "in type class instance"
715− , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
716− , Box.vcat Box.left (map typeAtomAsBox ts)
717− ]
718− ]
719− renderHint (ErrorCheckingKind ty) =
720− paras [ lineWithLevel "checking kind of type "
721− , indent $ typeAsBox ty
722− ]
723− renderHint (ErrorInferringType expr) =
724− paras [ lineWithLevel "inferring type of value "
725− , indent $ prettyPrintValue expr
726− ]
727− renderHint (ErrorCheckingType expr ty) =
728− paras [ lineWithLevel "checking that value "
729− , indent $ prettyPrintValue expr
730− , line "has type"
731− , indent $ typeAsBox ty
732− ]
733− renderHint (ErrorInApplication f t a) =
734− paras [ lineWithLevel "applying function"
735− , indent $ prettyPrintValue f
736− , line "of type"
737− , indent $ typeAsBox t
738− , line "to argument"
739− , indent $ prettyPrintValue a
740− ]
741− renderHint (ErrorInDataConstructor nm) =
742− lineWithLevel $ "in data constructor " ++ runProperName nm ++ ":"
743− renderHint (ErrorInTypeConstructor nm) =
744− lineWithLevel $ "in type constructor " ++ runProperName nm ++ ":"
745− renderHint (ErrorInBindingGroup nms) =
746− lineWithLevel $ "in binding group " ++ intercalate ", " (map showIdent nms) ++ ":"
747− renderHint ErrorInDataBindingGroup =
748− lineWithLevel "in data binding group:"
749− renderHint (ErrorInTypeSynonym name) =
750− lineWithLevel $ "in type synonym " ++ runProperName name ++ ":"
751− renderHint (ErrorInValueDeclaration n) =
752− lineWithLevel $ "in value declaration " ++ showIdent n ++ ":"
753− renderHint (ErrorInTypeDeclaration n) =
754− lineWithLevel $ "in type declaration for " ++ showIdent n ++ ":"
755− renderHint (ErrorInForeignImport nm) =
756− lineWithLevel $ "in foreign import " ++ showIdent nm ++ ":"
757− renderHint (PositionedError srcSpan) =
758− lineWithLevel $ "at " ++ displaySourceSpan srcSpan ++ ":"
759−
760− lineWithLevel :: String -> Box.Box
761− lineWithLevel text = line $ show level ++ " " ++ text
762807
763808 levelText :: String
764809 levelText = case level of
765810 Error -> "error"
766811 Warning -> "warning"
767812
768− suggestions :: SimpleErrorMessage -> [Box.Box]
769− suggestions (ConflictingImport nm im) = [ line $ "Possible fix: hide " ++ show nm ++ " when importing " ++ runModuleName im ++ ":"
770− , indent . line $ "import " ++ runModuleName im ++ " hiding (" ++ nm ++ ")"
771− ]
772− suggestions (TypesDoNotUnify t1 t2)
773− | isObject t1 && isFunction t2 = [line "Note that function composition in PureScript is defined using (<<<)"]
774− | otherwise = []
775− suggestions _ = []
776−
777813 paras :: [Box.Box] -> Box.Box
778814 paras = Box.vcat Box.left
779815
@@ -786,19 +822,6 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
786822 prettyPrintExport (ModuleRef name) = "module " ++ runModuleName name
787823 prettyPrintExport (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
788824
789− -- Hints get added at the front, so we need to reverse them before rendering
790− reverseHints :: ErrorMessage -> ErrorMessage
791− reverseHints (ErrorMessage hints simple) = ErrorMessage (reverse hints) simple
792−
793− -- | Put positional hints at the front of the list
794− positionHintsFirst :: ErrorMessage -> ErrorMessage
795− positionHintsFirst (ErrorMessage hints simple) = ErrorMessage (uncurry (++) $ partition (isPositionHint . hintCategory) hints) simple
796− where
797− isPositionHint :: HintCategory -> Bool
798− isPositionHint PositionHint = True
799− isPositionHint OtherHint = True
800− isPositionHint _ = False
801−
802825 -- | Simplify an error message
803826 simplifyErrorMessage :: ErrorMessage -> ErrorMessage
804827 simplifyErrorMessage (ErrorMessage hints simple) = ErrorMessage (simplifyHints hints) simple