@@ -20,7 +20,7 @@
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, nubBy, partition)
23+import Data.List (intercalate, transpose, nub, nubBy)
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)
@@ -41,8 +41,8 @@ import Control.Applicative ((<$>), (<*>), Applicative, pure)
41import Control.Monad.Trans.State.Lazy
41import Control.Monad.Trans.State.Lazy
42import Control.Arrow(first)
42import Control.Arrow(first)
44+import Language.PureScript.Crash
44import Language.PureScript.AST
45import Language.PureScript.AST
45−import Language.PureScript.Environment (isObject, isFunction)
46import Language.PureScript.Pretty
46import Language.PureScript.Pretty
47import Language.PureScript.Types
47import Language.PureScript.Types
48import Language.PureScript.Names
48import Language.PureScript.Names
@@ -56,19 +56,16 @@ import Text.Parsec.Error (Message(..))
57-- | A type of error messages
57-- | A type of error messages
58data SimpleErrorMessage
58data SimpleErrorMessage
59− = ErrorParsingExterns P.ParseError
60− | ErrorParsingFFIModule FilePath
59+ = ErrorParsingFFIModule FilePath
61 | ErrorParsingModule P.ParseError
60 | ErrorParsingModule P.ParseError
62 | MissingFFIModule ModuleName
61 | MissingFFIModule ModuleName
63 | MultipleFFIModules ModuleName [FilePath]
62 | MultipleFFIModules ModuleName [FilePath]
64 | UnnecessaryFFIModule ModuleName FilePath
63 | UnnecessaryFFIModule ModuleName FilePath
65− | InvalidExternsFile FilePath
66 | CannotGetFileInfo FilePath
64 | CannotGetFileInfo FilePath
67 | CannotReadFile FilePath
65 | CannotReadFile FilePath
68 | CannotWriteFile FilePath
66 | CannotWriteFile FilePath
69 | InfiniteType Type
67 | InfiniteType Type
70 | InfiniteKind Kind
68 | InfiniteKind Kind
71− | CannotReorderOperators
72 | MultipleFixities Ident
69 | MultipleFixities Ident
73 | OrphanTypeDeclaration Ident
70 | OrphanTypeDeclaration Ident
74 | OrphanFixityDeclaration String
71 | OrphanFixityDeclaration String
@@ -108,11 +105,9 @@ data SimpleErrorMessage
108 | CycleInTypeSynonym (Maybe ProperName)
105 | CycleInTypeSynonym (Maybe ProperName)
109 | CycleInModules [ModuleName]
106 | CycleInModules [ModuleName]
110 | NameIsUndefined Ident
107 | NameIsUndefined Ident
111− | NameNotInScope Ident
112 | UndefinedTypeVariable ProperName
108 | UndefinedTypeVariable ProperName
113 | PartiallyAppliedSynonym (Qualified ProperName)
109 | PartiallyAppliedSynonym (Qualified ProperName)
114 | EscapedSkolem (Maybe Expr)
110 | EscapedSkolem (Maybe Expr)
115− | UnspecifiedSkolemScope
116 | TypesDoNotUnify Type Type
111 | TypesDoNotUnify Type Type
117 | KindsDoNotUnify Kind Kind
112 | KindsDoNotUnify Kind Kind
118 | ConstrainedTypeUnified Type Type
113 | ConstrainedTypeUnified Type Type
@@ -126,23 +121,23 @@ data SimpleErrorMessage
126 | ArgListLengthsDiffer Ident
121 | ArgListLengthsDiffer Ident
127 | OverlappingArgNames (Maybe Ident)
122 | OverlappingArgNames (Maybe Ident)
128 | MissingClassMember Ident
123 | MissingClassMember Ident
129− | ExtraneousClassMember Ident
124+ | ExtraneousClassMember Ident (Qualified ProperName)
130 | ExpectedType Type Kind
125 | ExpectedType Type Kind
131 | IncorrectConstructorArity (Qualified ProperName)
126 | IncorrectConstructorArity (Qualified ProperName)
132− | SubsumptionCheckFailed
133 | ExprDoesNotHaveType Expr Type
127 | ExprDoesNotHaveType Expr Type
134− | PropertyIsMissing String Type
128+ | PropertyIsMissing String
129+ | AdditionalProperty String
135 | CannotApplyFunction Type Expr
130 | CannotApplyFunction Type Expr
136 | TypeSynonymInstance
131 | TypeSynonymInstance
137 | OrphanInstance Ident (Qualified ProperName) [Type]
132 | OrphanInstance Ident (Qualified ProperName) [Type]
138− | InvalidNewtype
133+ | InvalidNewtype ProperName
139 | InvalidInstanceHead Type
134 | InvalidInstanceHead Type
140 | TransitiveExportError DeclarationRef [DeclarationRef]
135 | TransitiveExportError DeclarationRef [DeclarationRef]
141 | ShadowedName Ident
136 | ShadowedName Ident
142 | ShadowedTypeVar String
137 | ShadowedTypeVar String
143 | UnusedTypeVar String
138 | UnusedTypeVar String
144 | WildcardInferredType Type
139 | WildcardInferredType Type
145− | MissingTypeDeclaration Ident
140+ | MissingTypeDeclaration Ident Type
146 | NotExhaustivePattern [[Binder]] Bool
141 | NotExhaustivePattern [[Binder]] Bool
147 | OverlappingPattern [[Binder]] Bool
142 | OverlappingPattern [[Binder]] Bool
148 | IncompleteExhaustivityCheck
143 | IncompleteExhaustivityCheck
@@ -153,14 +148,15 @@ data SimpleErrorMessage
154-- | Error message hints, providing more detailed information about failure.
149-- | Error message hints, providing more detailed information about failure.
155data ErrorMessageHint
150data ErrorMessageHint
156− = NotYetDefined [Ident]
157− | ErrorUnifyingTypes Type Type
151+ = ErrorUnifyingTypes Type Type
158 | ErrorInExpression Expr
152 | ErrorInExpression Expr
159 | ErrorInModule ModuleName
153 | ErrorInModule ModuleName
160 | ErrorInInstance (Qualified ProperName) [Type]
154 | ErrorInInstance (Qualified ProperName) [Type]
161 | ErrorInSubsumption Type Type
155 | ErrorInSubsumption Type Type
156+ | ErrorCheckingAccessor Expr String
162 | ErrorCheckingType Expr Type
157 | ErrorCheckingType Expr Type
163 | ErrorCheckingKind Type
158 | ErrorCheckingKind Type
159+ | ErrorCheckingGuard
164 | ErrorInferringType Expr
160 | ErrorInferringType Expr
165 | ErrorInApplication Expr Type Expr
161 | ErrorInApplication Expr Type Expr
166 | ErrorInDataConstructor ProperName
162 | ErrorInDataConstructor ProperName
@@ -196,19 +192,16 @@ instance UnificationError Kind ErrorMessage where
197errorCode :: ErrorMessage -> String
193errorCode :: ErrorMessage -> String
198errorCode em = case unwrapErrorMessage em of
194errorCode em = case unwrapErrorMessage em of
199− ErrorParsingExterns{} -> "ErrorParsingExterns"
200 ErrorParsingFFIModule{} -> "ErrorParsingFFIModule"
195 ErrorParsingFFIModule{} -> "ErrorParsingFFIModule"
201 ErrorParsingModule{} -> "ErrorParsingModule"
196 ErrorParsingModule{} -> "ErrorParsingModule"
202 MissingFFIModule{} -> "MissingFFIModule"
197 MissingFFIModule{} -> "MissingFFIModule"
203 MultipleFFIModules{} -> "MultipleFFIModules"
198 MultipleFFIModules{} -> "MultipleFFIModules"
204 UnnecessaryFFIModule{} -> "UnnecessaryFFIModule"
199 UnnecessaryFFIModule{} -> "UnnecessaryFFIModule"
205− InvalidExternsFile{} -> "InvalidExternsFile"
206 CannotGetFileInfo{} -> "CannotGetFileInfo"
200 CannotGetFileInfo{} -> "CannotGetFileInfo"
207 CannotReadFile{} -> "CannotReadFile"
201 CannotReadFile{} -> "CannotReadFile"
208 CannotWriteFile{} -> "CannotWriteFile"
202 CannotWriteFile{} -> "CannotWriteFile"
209 InfiniteType{} -> "InfiniteType"
203 InfiniteType{} -> "InfiniteType"
210 InfiniteKind{} -> "InfiniteKind"
204 InfiniteKind{} -> "InfiniteKind"
211− CannotReorderOperators -> "CannotReorderOperators"
212 MultipleFixities{} -> "MultipleFixities"
205 MultipleFixities{} -> "MultipleFixities"
213 OrphanTypeDeclaration{} -> "OrphanTypeDeclaration"
206 OrphanTypeDeclaration{} -> "OrphanTypeDeclaration"
214 OrphanFixityDeclaration{} -> "OrphanFixityDeclaration"
207 OrphanFixityDeclaration{} -> "OrphanFixityDeclaration"
@@ -248,11 +241,9 @@ errorCode em = case unwrapErrorMessage em of
248 CycleInTypeSynonym{} -> "CycleInTypeSynonym"
241 CycleInTypeSynonym{} -> "CycleInTypeSynonym"
249 CycleInModules{} -> "CycleInModules"
242 CycleInModules{} -> "CycleInModules"
250 NameIsUndefined{} -> "NameIsUndefined"
243 NameIsUndefined{} -> "NameIsUndefined"
251− NameNotInScope{} -> "NameNotInScope"
252 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
244 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
253 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
245 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
254 EscapedSkolem{} -> "EscapedSkolem"
246 EscapedSkolem{} -> "EscapedSkolem"
255− UnspecifiedSkolemScope -> "UnspecifiedSkolemScope"
256 TypesDoNotUnify{} -> "TypesDoNotUnify"
247 TypesDoNotUnify{} -> "TypesDoNotUnify"
257 KindsDoNotUnify{} -> "KindsDoNotUnify"
248 KindsDoNotUnify{} -> "KindsDoNotUnify"
258 ConstrainedTypeUnified{} -> "ConstrainedTypeUnified"
249 ConstrainedTypeUnified{} -> "ConstrainedTypeUnified"
@@ -269,13 +260,13 @@ errorCode em = case unwrapErrorMessage em of
269 ExtraneousClassMember{} -> "ExtraneousClassMember"
260 ExtraneousClassMember{} -> "ExtraneousClassMember"
270 ExpectedType{} -> "ExpectedType"
261 ExpectedType{} -> "ExpectedType"
271 IncorrectConstructorArity{} -> "IncorrectConstructorArity"
262 IncorrectConstructorArity{} -> "IncorrectConstructorArity"
272− SubsumptionCheckFailed -> "SubsumptionCheckFailed"
273 ExprDoesNotHaveType{} -> "ExprDoesNotHaveType"
263 ExprDoesNotHaveType{} -> "ExprDoesNotHaveType"
274 PropertyIsMissing{} -> "PropertyIsMissing"
264 PropertyIsMissing{} -> "PropertyIsMissing"
265+ AdditionalProperty{} -> "AdditionalProperty"
275 CannotApplyFunction{} -> "CannotApplyFunction"
266 CannotApplyFunction{} -> "CannotApplyFunction"
276 TypeSynonymInstance -> "TypeSynonymInstance"
267 TypeSynonymInstance -> "TypeSynonymInstance"
277 OrphanInstance{} -> "OrphanInstance"
268 OrphanInstance{} -> "OrphanInstance"
278− InvalidNewtype -> "InvalidNewtype"
269+ InvalidNewtype{} -> "InvalidNewtype"
279 InvalidInstanceHead{} -> "InvalidInstanceHead"
270 InvalidInstanceHead{} -> "InvalidInstanceHead"
280 TransitiveExportError{} -> "TransitiveExportError"
271 TransitiveExportError{} -> "TransitiveExportError"
281 ShadowedName{} -> "ShadowedName"
272 ShadowedName{} -> "ShadowedName"
@@ -362,7 +353,6 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
362 gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
353 gSimple (TypesDoNotUnify t1 t2) = TypesDoNotUnify <$> f t1 <*> f t2
363 gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> f t1 <*> f t2
354 gSimple (ConstrainedTypeUnified t1 t2) = ConstrainedTypeUnified <$> f t1 <*> f t2
364 gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> f t
355 gSimple (ExprDoesNotHaveType e t) = ExprDoesNotHaveType e <$> f t
365− gSimple (PropertyIsMissing s t) = PropertyIsMissing s <$> f t
366 gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
356 gSimple (CannotApplyFunction t e) = CannotApplyFunction <$> f t <*> pure e
367 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
357 gSimple (InvalidInstanceHead t) = InvalidInstanceHead <$> f t
368 gSimple other = pure other
358 gSimple other = pure other
@@ -377,17 +367,18 @@ onTypesInErrorMessageM f (ErrorMessage hints simple) = ErrorMessage <$> traverse
377-- Pretty print a single error, simplifying if necessary
367-- Pretty print a single error, simplifying if necessary
379prettyPrintSingleError :: Bool -> Level -> ErrorMessage -> State UnknownMap Box.Box
369prettyPrintSingleError :: Bool -> Level -> ErrorMessage -> State UnknownMap Box.Box
380−prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFirst . reverseHints <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
370+prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInErrorMessageM replaceUnknowns (if full then e else simplifyErrorMessage e)
383 -- Pretty print an ErrorMessage
373 -- Pretty print an ErrorMessage
384 prettyPrintErrorMessage :: ErrorMessage -> Box.Box
374 prettyPrintErrorMessage :: ErrorMessage -> Box.Box
385 prettyPrintErrorMessage (ErrorMessage hints simple) =
375 prettyPrintErrorMessage (ErrorMessage hints simple) =
387− map renderHint hints ++
377+ [ foldr renderHint (indent (renderSimpleErrorMessage simple)) hints
388− renderSimpleErrorMessage simple :
378+ , Box.moveDown 1 $ paras [ line $ "See " ++ wikiUri ++ " for more information, "
389− suggestions simple ++
390− [line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."]
379+ , line $ "or to contribute content related to this " ++ levelText ++ "."
392 wikiUri :: String
383 wikiUri :: String
393 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
384 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
@@ -405,12 +396,8 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
405 paras [ line "Unable to write file: "
396 paras [ line "Unable to write file: "
406 , indent . line $ path
397 , indent . line $ path
408− renderSimpleErrorMessage (ErrorParsingExterns err) =
409− paras [ lineWithLevel "parsing externs files: "
410− , prettyPrintParseError err
412 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
399 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
413− paras [ line "Unable to parse module from FFI file: "
400+ paras [ line "Unable to parse foreign module:"
414 , indent . line $ path
401 , indent . line $ path
416 renderSimpleErrorMessage (ErrorParsingModule err) =
403 renderSimpleErrorMessage (ErrorParsingModule err) =
@@ -418,29 +405,22 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
418 , prettyPrintParseError err
405 , prettyPrintParseError err
420 renderSimpleErrorMessage (MissingFFIModule mn) =
407 renderSimpleErrorMessage (MissingFFIModule mn) =
421− line $ "Missing FFI implementations for module " ++ runModuleName mn
408+ line $ "The foreign module implementation for module " ++ runModuleName mn ++ " is missing."
422 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
409 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 ++ ": "
424 , indent . line $ path
411 , indent . line $ path
412+ , line $ "Module " ++ runModuleName mn ++ " does not contain any foreign import declarations, so a foreign module is not necessary."
426 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
414 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 ++ ": "
428 , indent . paras $ map line paths
416 , indent . paras $ map line paths
430− renderSimpleErrorMessage (InvalidExternsFile path) =
431− paras [ line "Externs file is invalid: "
432− , indent . line $ path
434 renderSimpleErrorMessage InvalidDoBind =
418 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."
436 renderSimpleErrorMessage InvalidDoLet =
420 renderSimpleErrorMessage InvalidDoLet =
437− line "Let statement cannot be the last statement in a do block. The last statement must be an expression."
421+ line "The last statement in a 'do' block must be an expression, but this block ends with a let binding."
438− renderSimpleErrorMessage CannotReorderOperators =
439− line "Unable to reorder operators"
440− renderSimpleErrorMessage UnspecifiedSkolemScope =
441− line "Skolem variable scope is unspecified"
442 renderSimpleErrorMessage OverlappingNamesInLet =
422 renderSimpleErrorMessage OverlappingNamesInLet =
443− line "Overlapping names in let binding."
423+ line "The same name was used more than once in a let binding."
444 renderSimpleErrorMessage (InfiniteType ty) =
424 renderSimpleErrorMessage (InfiniteType ty) =
445 paras [ line "An infinite type was inferred for an expression: "
425 paras [ line "An infinite type was inferred for an expression: "
446 , indent $ typeAsBox ty
426 , indent $ typeAsBox ty
@@ -450,17 +430,17 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
450 , indent $ line $ prettyPrintKind ki
430 , indent $ line $ prettyPrintKind ki
452 renderSimpleErrorMessage (MultipleFixities name) =
432 renderSimpleErrorMessage (MultipleFixities name) =
453− line $ "Multiple fixity declarations for " ++ showIdent name
433+ line $ "There are multiple fixity/precedence declarations for " ++ showIdent name
454 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
434 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."
456 renderSimpleErrorMessage (OrphanFixityDeclaration op) =
436 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."
458 renderSimpleErrorMessage (RedefinedModule name filenames) =
438 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:")
460 , indent . paras $ map (line . displaySourceSpan) filenames
440 , indent . paras $ map (line . displaySourceSpan) filenames
462 renderSimpleErrorMessage (RedefinedIdent name) =
442 renderSimpleErrorMessage (RedefinedIdent name) =
463− line $ "Name " ++ showIdent name ++ " has been defined multiple times"
443+ line $ "The value " ++ showIdent name ++ " has been defined multiple times"
464 renderSimpleErrorMessage (UnknownModule mn) =
444 renderSimpleErrorMessage (UnknownModule mn) =
465 line $ "Unknown module " ++ runModuleName mn
445 line $ "Unknown module " ++ runModuleName mn
466 renderSimpleErrorMessage (UnknownType name) =
446 renderSimpleErrorMessage (UnknownType name) =
@@ -474,25 +454,36 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
474 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
454 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
475 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
455 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
476 renderSimpleErrorMessage (UnknownImportType mn name) =
456 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."
478 renderSimpleErrorMessage (UnknownExportType name) =
460 renderSimpleErrorMessage (UnknownExportType name) =
479 line $ "Cannot export unknown type " ++ runProperName name
461 line $ "Cannot export unknown type " ++ runProperName name
480 renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
462 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."
482 renderSimpleErrorMessage (UnknownExportTypeClass name) =
466 renderSimpleErrorMessage (UnknownExportTypeClass name) =
483 line $ "Cannot export unknown type class " ++ runProperName name
467 line $ "Cannot export unknown type class " ++ runProperName name
484 renderSimpleErrorMessage (UnknownImportValue mn name) =
468 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."
486 renderSimpleErrorMessage (UnknownExportValue name) =
472 renderSimpleErrorMessage (UnknownExportValue name) =
487 line $ "Cannot export unknown value " ++ showIdent name
473 line $ "Cannot export unknown value " ++ showIdent name
488 renderSimpleErrorMessage (UnknownExportModule name) =
474 renderSimpleErrorMessage (UnknownExportModule name) =
475+ paras [ line $ "Cannot export unknown module " ++ runModuleName name
489− line $ "Cannot export unknown module " ++ runModuleName name ++ ", it either does not exist or has not been imported by the current module"
476+ , line "It either does not exist or has not been imported by the current module."
490 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
478 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
491 line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
479 line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
492 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
480 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."
494 renderSimpleErrorMessage (ConflictingImport nm mn) =
482 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 ++ ")"
496 renderSimpleErrorMessage (ConflictingImports nm m1 m2) =
487 renderSimpleErrorMessage (ConflictingImports nm m1 m2) =
497 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
488 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
498 renderSimpleErrorMessage (ConflictingTypeDecls nm) =
489 renderSimpleErrorMessage (ConflictingTypeDecls nm) =
@@ -500,13 +491,13 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
500 renderSimpleErrorMessage (ConflictingCtorDecls nm) =
491 renderSimpleErrorMessage (ConflictingCtorDecls nm) =
501 line $ "Conflicting data constructor declarations for " ++ runProperName nm
492 line $ "Conflicting data constructor declarations for " ++ runProperName nm
502 renderSimpleErrorMessage (TypeConflictsWithClass nm) =
493 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."
504 renderSimpleErrorMessage (CtorConflictsWithClass nm) =
495 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."
506 renderSimpleErrorMessage (ClassConflictsWithType nm) =
497 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."
508 renderSimpleErrorMessage (ClassConflictsWithCtor nm) =
499 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."
510 renderSimpleErrorMessage (DuplicateModuleName mn) =
501 renderSimpleErrorMessage (DuplicateModuleName mn) =
511 line $ "Module " ++ runModuleName mn ++ " has been defined multiple times."
502 line $ "Module " ++ runModuleName mn ++ " has been defined multiple times."
512 renderSimpleErrorMessage (DuplicateClassExport nm) =
503 renderSimpleErrorMessage (DuplicateClassExport nm) =
@@ -514,19 +505,24 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
514 renderSimpleErrorMessage (DuplicateValueExport nm) =
505 renderSimpleErrorMessage (DuplicateValueExport nm) =
515 line $ "Duplicate export declaration for value " ++ showIdent nm
506 line $ "Duplicate export declaration for value " ++ showIdent nm
516 renderSimpleErrorMessage (CycleInDeclaration nm) =
507 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."
518 renderSimpleErrorMessage (CycleInModules mns) =
509 renderSimpleErrorMessage (CycleInModules mns) =
519− line $ "Cycle in module dependencies: " ++ intercalate ", " (map runModuleName mns)
510+ paras [ line $ "There is a cycle in module dependencies in these modules: "
511+ , indent $ paras (map (line . runModuleName) mns)
520− renderSimpleErrorMessage (CycleInTypeSynonym pn) =
513+ renderSimpleErrorMessage (CycleInTypeSynonym name) =
521− line $ "Cycle in type synonym" ++ foldMap ((" " ++) . runProperName) pn
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."
522 renderSimpleErrorMessage (NameIsUndefined ident) =
520 renderSimpleErrorMessage (NameIsUndefined ident) =
523− line $ showIdent ident ++ " is undefined"
521+ line $ "Value " ++ showIdent ident ++ " is undefined."
524− renderSimpleErrorMessage (NameNotInScope ident) =
525− line $ showIdent ident ++ " may not be defined in the current scope"
526 renderSimpleErrorMessage (UndefinedTypeVariable name) =
522 renderSimpleErrorMessage (UndefinedTypeVariable name) =
527− line $ "Type variable " ++ runProperName name ++ " is undefined"
523+ line $ "Type variable " ++ runProperName name ++ " is undefined."
528 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
524 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
529− paras [ line $ "Partially applied type synonym " ++ showQualified runProperName name
525+ paras [ line $ "Type synonym " ++ showQualified runProperName name ++ " is partially applied."
530 , 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."
532 renderSimpleErrorMessage (EscapedSkolem binding) =
528 renderSimpleErrorMessage (EscapedSkolem binding) =
@@ -535,70 +531,72 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
535 , indent $ prettyPrintValue expr
531 , indent $ prettyPrintValue expr
536 ]) binding
532 ]) binding
537 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
533 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
538− = paras [ line "Cannot unify type"
534+ = paras [ line "Could not match type"
539 , indent $ typeAsBox t1
535 , indent $ typeAsBox t1
540 , line "with type"
536 , line "with type"
541 , indent $ typeAsBox t2
537 , indent $ typeAsBox t2
543 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
539 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
544− paras [ line "Cannot unify kind"
540+ paras [ line "Could not match kind"
545 , indent $ line $ prettyPrintKind k1
541 , indent $ line $ prettyPrintKind k1
546 , line "with kind"
542 , line "with kind"
547 , indent $ line $ prettyPrintKind k2
543 , indent $ line $ prettyPrintKind k2
549 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
545 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
550− paras [ line "Cannot unify constrained type"
546+ paras [ line "Could not match constrained type"
551 , indent $ typeAsBox t1
547 , indent $ typeAsBox t1
552 , line "with type"
548 , line "with type"
553 , indent $ typeAsBox t2
549 , indent $ typeAsBox t2
555 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
551 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
556− paras [ line "Overlapping instances found for"
552+ paras [ line "Overlapping type class instances found for"
557 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
553 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
558 , Box.vcat Box.left (map typeAtomAsBox ts)
554 , Box.vcat Box.left (map typeAtomAsBox ts)
560 , line "The following instances were found:"
556 , line "The following instances were found:"
561 , 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)
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."
563− renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
561+ renderSimpleErrorMessage OverlappingInstances{} = internalError "OverlappingInstances: empty instance list"
564 renderSimpleErrorMessage (NoInstanceFound nm ts) =
562 renderSimpleErrorMessage (NoInstanceFound nm ts) =
565− paras [ line "No instance found for"
563+ paras [ line "No type class instance was found for"
566 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
564 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
567 , Box.vcat Box.left (map typeAtomAsBox ts)
565 , Box.vcat Box.left (map typeAtomAsBox ts)
570 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
568 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
571− paras [ line "Instance for"
569+ paras [ line "Type class instance for"
572 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
570 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
573 , Box.vcat Box.left (map typeAtomAsBox ts)
571 , Box.vcat Box.left (map typeAtomAsBox ts)
575 , line "is possibly infinite."
573 , line "is possibly infinite."
577 renderSimpleErrorMessage (CannotDerive nm ts) =
575 renderSimpleErrorMessage (CannotDerive nm ts) =
578− paras [ line "Cannot derive an instance for"
576+ paras [ line "Cannot derive a type class instance for"
579 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
577 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
580 , Box.vcat Box.left (map typeAtomAsBox ts)
578 , Box.vcat Box.left (map typeAtomAsBox ts)
583 renderSimpleErrorMessage (CannotFindDerivingType nm) =
581 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."
585 renderSimpleErrorMessage (DuplicateLabel l expr) =
583 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." ]
587 <> foldMap (\expr' -> [ line "Relevant expression: "
585 <> foldMap (\expr' -> [ line "Relevant expression: "
588 , indent $ prettyPrintValue expr'
586 , indent $ prettyPrintValue expr'
590 renderSimpleErrorMessage (DuplicateTypeArgument name) =
588 renderSimpleErrorMessage (DuplicateTypeArgument name) =
591− line $ "Duplicate type argument " ++ show name
589+ line $ "Type argument " ++ show name ++ " appears more than once."
592 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
590 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
593− line $ "Duplicate value declaration for " ++ showIdent nm
591+ line $ "Multiple value declarations exist for " ++ showIdent nm ++ "."
594 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
592 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
595 line $ "Argument list lengths differ in declaration " ++ showIdent ident
593 line $ "Argument list lengths differ in declaration " ++ showIdent ident
596 renderSimpleErrorMessage (OverlappingArgNames ident) =
594 renderSimpleErrorMessage (OverlappingArgNames ident) =
597 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
595 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
598 renderSimpleErrorMessage (MissingClassMember ident) =
596 renderSimpleErrorMessage (MissingClassMember ident) =
599− line $ "Member " ++ showIdent ident ++ " has not been implemented"
597+ line $ "Type class member " ++ showIdent ident ++ " has not been implemented."
600− renderSimpleErrorMessage (ExtraneousClassMember ident) =
598+ renderSimpleErrorMessage (ExtraneousClassMember ident className) =
601− line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
599+ line $ showIdent ident ++ " is not a member of type class " ++ showQualified runProperName className
602 renderSimpleErrorMessage (ExpectedType ty kind) =
600 renderSimpleErrorMessage (ExpectedType ty kind) =
603 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
601 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
604 , line "The error arises from the type"
602 , line "The error arises from the type"
@@ -608,29 +606,27 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
608 , line "instead."
606 , line "instead."
610 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
608 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
611− line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
609+ line $ "Data constructor " ++ showQualified runProperName nm ++ " was given the wrong number of arguments in a case expression."
612− renderSimpleErrorMessage SubsumptionCheckFailed = line "Unable to check type subsumption"
613 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
610 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
614 paras [ line "Expression"
611 paras [ line "Expression"
615 , indent $ prettyPrintValue expr
612 , indent $ prettyPrintValue expr
616 , line "does not have type"
613 , line "does not have type"
617 , indent $ typeAsBox ty
614 , indent $ typeAsBox ty
619− renderSimpleErrorMessage (PropertyIsMissing prop row) =
616+ renderSimpleErrorMessage (PropertyIsMissing prop) =
621− , indent $ prettyPrintRowWith '(' ')' row
622− , line $ "lacks required property " ++ show prop
617+ line $ "Type of expression lacks required label " ++ show prop ++ "."
623− ]
618+ renderSimpleErrorMessage (AdditionalProperty prop) =
619+ line $ "Type of expression contains additional label " ++ show prop ++ "."
624 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
620 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
625− paras [ line "Cannot apply function of type"
621+ paras [ line "A function of type"
626 , indent $ typeAsBox fn
622 , indent $ typeAsBox fn
627− , line "to argument"
623+ , line "can not be applied to the argument"
628 , indent $ prettyPrintValue arg
624 , indent $ prettyPrintValue arg
630 renderSimpleErrorMessage TypeSynonymInstance =
626 renderSimpleErrorMessage TypeSynonymInstance =
631− line "Type synonym instances are disallowed"
627+ line "Type class instances for type synonyms are disallowed."
632 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
628 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
633− paras [ line $ "Instance " ++ showIdent nm ++ " for "
629+ paras [ line $ "Type class instance " ++ showIdent nm ++ " for "
634 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
630 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
635 , Box.vcat Box.left (map typeAtomAsBox ts)
631 , Box.vcat Box.left (map typeAtomAsBox ts)
@@ -638,39 +634,44 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
638 , 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."
639 , 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."
641− renderSimpleErrorMessage InvalidNewtype =
637+ renderSimpleErrorMessage (InvalidNewtype name) =
638+ paras [ line $ "Newtype " ++ runProperName name ++ " is invalid."
642− line "Newtypes must define a single constructor with a single argument"
639+ , line "Newtypes must define a single constructor with a single argument."
643 renderSimpleErrorMessage (InvalidInstanceHead ty) =
641 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"
645 , indent $ typeAsBox ty
643 , 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."
647 renderSimpleErrorMessage (TransitiveExportError x ys) =
646 renderSimpleErrorMessage (TransitiveExportError x ys) =
648 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
647 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
649 : map (line . prettyPrintExport) ys
648 : map (line . prettyPrintExport) ys
650 renderSimpleErrorMessage (ShadowedName nm) =
649 renderSimpleErrorMessage (ShadowedName nm) =
651− line $ "Name '" ++ showIdent nm ++ "' was shadowed"
650+ line $ "Name '" ++ showIdent nm ++ "' was shadowed."
652 renderSimpleErrorMessage (ShadowedTypeVar tv) =
651 renderSimpleErrorMessage (ShadowedTypeVar tv) =
653− line $ "Type variable '" ++ tv ++ "' was shadowed"
652+ line $ "Type variable '" ++ tv ++ "' was shadowed."
654 renderSimpleErrorMessage (UnusedTypeVar tv) =
653 renderSimpleErrorMessage (UnusedTypeVar tv) =
655− line $ "Type variable '" ++ tv ++ "' was declared but not used"
654+ line $ "Type variable '" ++ tv ++ "' was declared but not used."
656 renderSimpleErrorMessage (ClassOperator className opName) =
655 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 ++ "."
658 , line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
657 , line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
659 , indent . line $ showIdent opName ++ " = someMember"
658 , indent . line $ showIdent opName ++ " = someMember"
661 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
660 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."
663 renderSimpleErrorMessage (ImportHidingModule name) =
662 renderSimpleErrorMessage (ImportHidingModule name) =
663+ paras [ line $ "'hiding' imports cannot be used to hide modules."
664− line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
664+ , line $ "An attempt was made to hide the import of " ++ runModuleName name
665 renderSimpleErrorMessage (WildcardInferredType ty) =
666 renderSimpleErrorMessage (WildcardInferredType ty) =
666− paras [ line "The wildcard type definition has the inferred type "
667+ paras [ line "Wildcard type definition has the inferred type "
667 , indent $ typeAsBox ty
668 , indent $ typeAsBox ty
669− renderSimpleErrorMessage (MissingTypeDeclaration ident) =
670+ renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
670 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
671 paras [ line $ "No type declaration was provided for the top-level declaration of " ++ showIdent ident ++ "."
671 , line "It is good practice to provide type declarations as a form of documentation."
672 , 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+ , line $ "The inferred type of " ++ showIdent ident ++ " was:"
673− , indent $ line $ showIdent ident ++ " :: _"
674+ , indent $ typeAsBox ty
675 renderSimpleErrorMessage (NotExhaustivePattern bs b) =
676 renderSimpleErrorMessage (NotExhaustivePattern bs b) =
676 paras $ [ line "A case expression could not be determined to cover all inputs."
677 paras $ [ line "A case expression could not be determined to cover all inputs."
@@ -685,95 +686,130 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
685 [ line "..." | not b ]
686 [ line "..." | not b ]
686 renderSimpleErrorMessage IncompleteExhaustivityCheck =
687 renderSimpleErrorMessage IncompleteExhaustivityCheck =
687 paras [ line "An exhaustivity check was abandoned due to too many possible cases."
688 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+ , line "You may want to decompose your data types into smaller types."
691− renderHint :: ErrorMessageHint -> Box.Box
692+ renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
692− renderHint (NotYetDefined names) =
693− line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
694− renderHint (ErrorUnifyingTypes t1 t2) =
693+ renderHint (ErrorUnifyingTypes t1 t2) detail =
695− paras [ lineWithLevel "unifying type "
694+ paras [ detail
695+ , Box.hsep 1 Box.top [ line "while trying to match type"
696− , indent $ typeAsBox t1
696+ , typeAsBox t1
697− , line "with type"
698+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "with type"
702+ renderHint (ErrorInExpression expr) detail =
704+ , Box.hsep 1 Box.top [ Box.text "in the expression"
705+ , prettyPrintValue expr
708+ renderHint (ErrorInModule mn) detail =
709+ paras [ line $ "in module " ++ runModuleName mn
712+ renderHint (ErrorInSubsumption t1 t2) detail =
714+ , Box.hsep 1 Box.top [ line "while checking that type"
717+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "is at least as general as type"
698− , indent $ typeAsBox t2
718+ , typeAsBox t2
721+ renderHint (ErrorInInstance nm ts) 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)
728+ renderHint (ErrorCheckingKind ty) detail =
730+ , Box.hsep 1 Box.top [ line "while checking the kind of"
734+ renderHint ErrorCheckingGuard detail =
736+ , line "while checking the type of a guard clause"
738+ renderHint (ErrorInferringType expr) detail =
740+ , Box.hsep 1 Box.top [ line "while inferring the type of"
741+ , prettyPrintValue expr
744+ renderHint (ErrorCheckingType expr ty) detail =
746+ , Box.hsep 1 Box.top [ line "while checking that expression"
747+ , prettyPrintValue expr
749+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "has type"
753+ renderHint (ErrorCheckingAccessor expr prop) detail =
755+ , Box.hsep 1 Box.top [ line "while checking type of property accessor"
756+ , prettyPrintValue (Accessor prop expr)
759+ renderHint (ErrorInApplication f t a) detail =
761+ , Box.hsep 1 Box.top [ line "while applying a function"
762+ , prettyPrintValue f
764+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "of type"
767+ , Box.moveRight 2 $ Box.hsep 1 Box.top [ line "to argument"
768+ , prettyPrintValue a
771+ renderHint (ErrorInDataConstructor nm) detail =
773+ , line $ "in data constructor " ++ runProperName nm
775+ renderHint (ErrorInTypeConstructor nm) detail =
777+ , line $ "in type constructor " ++ runProperName nm
779+ renderHint (ErrorInBindingGroup nms) detail =
781+ , line $ "in binding group " ++ intercalate ", " (map showIdent nms)
783+ renderHint ErrorInDataBindingGroup detail =
785+ , line "in data binding group"
787+ renderHint (ErrorInTypeSynonym name) detail =
789+ , line $ "in type synonym " ++ runProperName name
791+ renderHint (ErrorInValueDeclaration n) detail =
793+ , line $ "in value declaration " ++ showIdent n
795+ renderHint (ErrorInTypeDeclaration n) detail =
797+ , line $ "in type declaration for " ++ showIdent n
799+ renderHint (ErrorInForeignImport nm) detail =
801+ , line $ "in foreign import " ++ showIdent nm
803+ renderHint (PositionedError srcSpan) detail =
804+ paras [ line $ "at " ++ displaySourceSpan srcSpan
700− renderHint (ErrorInExpression expr) =
701− paras [ lineWithLevel "in expression:"
702− , indent $ prettyPrintValue expr
704− renderHint (ErrorInModule mn) =
705− paras [ lineWithLevel $ "in module " ++ runModuleName mn ++ ":"
707− renderHint (ErrorInSubsumption t1 t2) =
708− paras [ lineWithLevel "checking that type "
709− , indent $ typeAsBox t1
710− , line "subsumes type"
711− , indent $ typeAsBox t2
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)
719− renderHint (ErrorCheckingKind ty) =
720− paras [ lineWithLevel "checking kind of type "
721− , indent $ typeAsBox ty
723− renderHint (ErrorInferringType expr) =
724− paras [ lineWithLevel "inferring type of value "
725− , indent $ prettyPrintValue expr
727− renderHint (ErrorCheckingType expr ty) =
728− paras [ lineWithLevel "checking that value "
729− , indent $ prettyPrintValue expr
731− , indent $ typeAsBox ty
733− renderHint (ErrorInApplication f t a) =
734− paras [ lineWithLevel "applying function"
735− , indent $ prettyPrintValue f
737− , indent $ typeAsBox t
738− , line "to argument"
739− , indent $ prettyPrintValue a
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 ++ ":"
760− lineWithLevel :: String -> Box.Box
761− lineWithLevel text = line $ show level ++ " " ++ text
763 levelText :: String
808 levelText :: String
764 levelText = case level of
809 levelText = case level of
765 Error -> "error"
810 Error -> "error"
766 Warning -> "warning"
811 Warning -> "warning"
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 ++ ")"
772− suggestions (TypesDoNotUnify t1 t2)
773− | isObject t1 && isFunction t2 = [line "Note that function composition in PureScript is defined using (<<<)"]
777 paras :: [Box.Box] -> Box.Box
813 paras :: [Box.Box] -> Box.Box
778 paras = Box.vcat Box.left
814 paras = Box.vcat Box.left
@@ -786,19 +822,6 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
786 prettyPrintExport (ModuleRef name) = "module " ++ runModuleName name
822 prettyPrintExport (ModuleRef name) = "module " ++ runModuleName name
787 prettyPrintExport (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
823 prettyPrintExport (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
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
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
797− isPositionHint :: HintCategory -> Bool
798− isPositionHint PositionHint = True
799− isPositionHint OtherHint = True
800− isPositionHint _ = False
802 -- | Simplify an error message
825 -- | Simplify an error message
803 simplifyErrorMessage :: ErrorMessage -> ErrorMessage
826 simplifyErrorMessage :: ErrorMessage -> ErrorMessage
804 simplifyErrorMessage (ErrorMessage hints simple) = ErrorMessage (simplifyHints hints) simple
827 simplifyErrorMessage (ErrorMessage hints simple) = ErrorMessage (simplifyHints hints) simple