@@ -41,6 +41,7 @@ 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
45import Language.PureScript.Pretty
46import Language.PureScript.Pretty
46import Language.PureScript.Types
47import Language.PureScript.Types
@@ -105,7 +106,6 @@ data SimpleErrorMessage
105 | CycleInTypeSynonym (Maybe ProperName)
106 | CycleInTypeSynonym (Maybe ProperName)
106 | CycleInModules [ModuleName]
107 | CycleInModules [ModuleName]
107 | NameIsUndefined Ident
108 | NameIsUndefined Ident
108− | NameNotInScope Ident
109 | UndefinedTypeVariable ProperName
109 | UndefinedTypeVariable ProperName
110 | PartiallyAppliedSynonym (Qualified ProperName)
110 | PartiallyAppliedSynonym (Qualified ProperName)
111 | EscapedSkolem (Maybe Expr)
111 | EscapedSkolem (Maybe Expr)
@@ -130,7 +130,7 @@ data SimpleErrorMessage
130 | CannotApplyFunction Type Expr
130 | CannotApplyFunction Type Expr
131 | TypeSynonymInstance
131 | TypeSynonymInstance
132 | OrphanInstance Ident (Qualified ProperName) [Type]
132 | OrphanInstance Ident (Qualified ProperName) [Type]
133− | InvalidNewtype
133+ | InvalidNewtype ProperName
134 | InvalidInstanceHead Type
134 | InvalidInstanceHead Type
135 | TransitiveExportError DeclarationRef [DeclarationRef]
135 | TransitiveExportError DeclarationRef [DeclarationRef]
136 | ShadowedName Ident
136 | ShadowedName Ident
@@ -241,7 +241,6 @@ errorCode em = case unwrapErrorMessage em of
241 CycleInTypeSynonym{} -> "CycleInTypeSynonym"
241 CycleInTypeSynonym{} -> "CycleInTypeSynonym"
242 CycleInModules{} -> "CycleInModules"
242 CycleInModules{} -> "CycleInModules"
243 NameIsUndefined{} -> "NameIsUndefined"
243 NameIsUndefined{} -> "NameIsUndefined"
244− NameNotInScope{} -> "NameNotInScope"
245 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
244 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
246 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
245 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
247 EscapedSkolem{} -> "EscapedSkolem"
246 EscapedSkolem{} -> "EscapedSkolem"
@@ -266,7 +265,7 @@ errorCode em = case unwrapErrorMessage em of
266 CannotApplyFunction{} -> "CannotApplyFunction"
265 CannotApplyFunction{} -> "CannotApplyFunction"
267 TypeSynonymInstance -> "TypeSynonymInstance"
266 TypeSynonymInstance -> "TypeSynonymInstance"
268 OrphanInstance{} -> "OrphanInstance"
267 OrphanInstance{} -> "OrphanInstance"
269− InvalidNewtype -> "InvalidNewtype"
268+ InvalidNewtype{} -> "InvalidNewtype"
270 InvalidInstanceHead{} -> "InvalidInstanceHead"
269 InvalidInstanceHead{} -> "InvalidInstanceHead"
271 TransitiveExportError{} -> "TransitiveExportError"
270 TransitiveExportError{} -> "TransitiveExportError"
272 ShadowedName{} -> "ShadowedName"
271 ShadowedName{} -> "ShadowedName"
@@ -403,18 +402,13 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
403 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
402 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
404 paras [ line "Unable to parse foreign module:"
403 paras [ line "Unable to parse foreign module:"
405 , indent . line $ path
404 , indent . line $ path
406− , line "Ensure that all foreign modules contain a single module header at the start of a line, as follows:"
407− , indent $ line "// module A.B.C"
409 renderSimpleErrorMessage (ErrorParsingModule err) =
406 renderSimpleErrorMessage (ErrorParsingModule err) =
410 paras [ line "Unable to parse module: "
407 paras [ line "Unable to parse module: "
411 , prettyPrintParseError err
408 , prettyPrintParseError err
413 renderSimpleErrorMessage (MissingFFIModule mn) =
410 renderSimpleErrorMessage (MissingFFIModule mn) =
414− paras [ line $ "The foreign module implementation for module " ++ runModuleName mn ++ " is missing."
411+ line $ "The foreign module implementation for module " ++ runModuleName mn ++ " is missing."
415− , line $ "Provide your foreign module implementation using the --ffi command line option, and ensure that your module contains the following module header:"
416− , indent . line $ "// module " ++ runModuleName mn
418 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
412 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
419 paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ runModuleName mn ++ ": "
413 paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ runModuleName mn ++ ": "
420 , indent . line $ path
414 , indent . line $ path
@@ -423,8 +417,6 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
423 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
417 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
424 paras [ line $ "Multiple foreign module implementations have been provided for module " ++ runModuleName mn ++ ": "
418 paras [ line $ "Multiple foreign module implementations have been provided for module " ++ runModuleName mn ++ ": "
425 , indent . paras $ map line paths
419 , indent . paras $ map line paths
426− , line "Foreign modules are identified by a unique module name, as follows:"
427− , indent $ line "// module A.B.C"
429 renderSimpleErrorMessage InvalidDoBind =
421 renderSimpleErrorMessage InvalidDoBind =
430 line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
422 line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
@@ -451,7 +443,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
451 , indent . paras $ map (line . displaySourceSpan) filenames
443 , indent . paras $ map (line . displaySourceSpan) filenames
453 renderSimpleErrorMessage (RedefinedIdent name) =
445 renderSimpleErrorMessage (RedefinedIdent name) =
454− line $ "The name " ++ showIdent name ++ " has been defined multiple times"
446+ line $ "The value " ++ showIdent name ++ " has been defined multiple times"
455 renderSimpleErrorMessage (UnknownModule mn) =
447 renderSimpleErrorMessage (UnknownModule mn) =
456 line $ "Unknown module " ++ runModuleName mn
448 line $ "Unknown module " ++ runModuleName mn
457 renderSimpleErrorMessage (UnknownType name) =
449 renderSimpleErrorMessage (UnknownType name) =
@@ -465,15 +457,21 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
465 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
457 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
466 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
458 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
467 renderSimpleErrorMessage (UnknownImportType mn name) =
459 renderSimpleErrorMessage (UnknownImportType mn name) =
468− line $ "The type " ++ runProperName name ++ " is not exported by the module " ++ runModuleName mn
460+ paras [ line $ "Cannot import the type " ++ runProperName name ++ " from module " ++ runModuleName mn
461+ , line "It either does not exist or the module does not export it."
469 renderSimpleErrorMessage (UnknownExportType name) =
463 renderSimpleErrorMessage (UnknownExportType name) =
470 line $ "Cannot export unknown type " ++ runProperName name
464 line $ "Cannot export unknown type " ++ runProperName name
471 renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
465 renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
472− line $ "The type class " ++ runProperName name ++ " is not exported by the module " ++ runModuleName mn
466+ paras [ line $ "Cannot import the type class " ++ runProperName name ++ " from module " ++ runModuleName mn
467+ , line "It either does not exist or the module does not export it."
473 renderSimpleErrorMessage (UnknownExportTypeClass name) =
469 renderSimpleErrorMessage (UnknownExportTypeClass name) =
474 line $ "Cannot export unknown type class " ++ runProperName name
470 line $ "Cannot export unknown type class " ++ runProperName name
475 renderSimpleErrorMessage (UnknownImportValue mn name) =
471 renderSimpleErrorMessage (UnknownImportValue mn name) =
476− line $ "The value " ++ showIdent name ++ " is not exported by the module " ++ runModuleName mn
472+ paras [ line $ "Cannot import the value " ++ showIdent name ++ " from module " ++ runModuleName mn
473+ , line "It either does not exist or the module does not export it."
477 renderSimpleErrorMessage (UnknownExportValue name) =
475 renderSimpleErrorMessage (UnknownExportValue name) =
478 line $ "Cannot export unknown value " ++ showIdent name
476 line $ "Cannot export unknown value " ++ showIdent name
479 renderSimpleErrorMessage (UnknownExportModule name) =
477 renderSimpleErrorMessage (UnknownExportModule name) =
@@ -481,7 +479,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
481 , line "It either does not exist or has not been imported by the current module."
479 , line "It either does not exist or has not been imported by the current module."
483 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
481 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
484− line $ "The data constructor " ++ runProperName dcon ++ " (for type " ++ runProperName tcon ++ ") is not exported by the module " ++ runModuleName mn
482+ line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
485 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
483 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
486 line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ ", as it has not been declared."
484 line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ ", as it has not been declared."
487 renderSimpleErrorMessage (ConflictingImport nm mn) =
485 renderSimpleErrorMessage (ConflictingImport nm mn) =
@@ -510,10 +508,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
510 renderSimpleErrorMessage (DuplicateValueExport nm) =
508 renderSimpleErrorMessage (DuplicateValueExport nm) =
511 line $ "Duplicate export declaration for value " ++ showIdent nm
509 line $ "Duplicate export declaration for value " ++ showIdent nm
512 renderSimpleErrorMessage (CycleInDeclaration nm) =
510 renderSimpleErrorMessage (CycleInDeclaration nm) =
513− paras [ line $ "The declaration of " ++ showIdent nm ++ " contains a cycle."
514− , line $ "The value of " ++ showIdent nm ++ " may not be defined here, so this reference is not allowed."
511+ line $ "The value of " ++ showIdent nm ++ " is undefined here, so this reference is not allowed."
515− , line "You might be able to evaluate this expression lazily, using something like Control.Lazy.fix"
517 renderSimpleErrorMessage (CycleInModules mns) =
512 renderSimpleErrorMessage (CycleInModules mns) =
518 line $ "There is a cycle in the module dependencies: " ++ intercalate ", " (map runModuleName mns)
513 line $ "There is a cycle in the module dependencies: " ++ intercalate ", " (map runModuleName mns)
519 renderSimpleErrorMessage (CycleInTypeSynonym name) =
514 renderSimpleErrorMessage (CycleInTypeSynonym name) =
@@ -524,9 +519,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
524 , line "Consider using a 'newtype' instead."
519 , line "Consider using a 'newtype' instead."
526 renderSimpleErrorMessage (NameIsUndefined ident) =
521 renderSimpleErrorMessage (NameIsUndefined ident) =
527− line $ "The name " ++ showIdent ident ++ " is undefined."
522+ line $ "The value " ++ showIdent ident ++ " is undefined."
528− renderSimpleErrorMessage (NameNotInScope ident) =
529− line $ "The name " ++ showIdent ident ++ " may not be defined in the current scope."
530 renderSimpleErrorMessage (UndefinedTypeVariable name) =
523 renderSimpleErrorMessage (UndefinedTypeVariable name) =
531 line $ "The type variable " ++ runProperName name ++ " is undefined."
524 line $ "The type variable " ++ runProperName name ++ " is undefined."
532 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
525 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
@@ -539,21 +532,21 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
539 , indent $ prettyPrintValue expr
532 , indent $ prettyPrintValue expr
540 ]) binding
533 ]) binding
541 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
534 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
542− = paras [ line "The type"
535+ = paras [ line "Could not match expected type"
543 , indent $ typeAsBox t1
536 , indent $ typeAsBox t1
544− , line "cannot be made equal to the type"
537+ , line "with actual type"
545 , indent $ typeAsBox t2
538 , indent $ typeAsBox t2
547 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
540 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
548− paras [ line "The kind"
541+ paras [ line "Could not match expected kind"
549 , indent $ line $ prettyPrintKind k1
542 , indent $ line $ prettyPrintKind k1
550− , line "cannot be made equal to the kind"
543+ , line "with actual kind"
551 , indent $ line $ prettyPrintKind k2
544 , indent $ line $ prettyPrintKind k2
553 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
546 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
554− paras [ line "The constrained type"
547+ paras [ line "Could not match the constrained type"
555 , indent $ typeAsBox t1
548 , indent $ typeAsBox t1
556− , line "cannot be made equal to the kind"
549+ , line "with type"
557 , indent $ typeAsBox t2
550 , indent $ typeAsBox t2
559 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
552 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
@@ -563,8 +556,10 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
564 , line "The following instances were found:"
557 , line "The following instances were found:"
565 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
558 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
559+ , line "Overlapping type class instances can lead to different behavior based on the order of module imports, and for that reason are not recommended."
560+ , line "They may be disallowed completely in a future version of the compiler."
567− renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
562+ renderSimpleErrorMessage OverlappingInstances{} = internalError "OverlappingInstances: empty instance list"
568 renderSimpleErrorMessage (NoInstanceFound nm ts) =
563 renderSimpleErrorMessage (NoInstanceFound nm ts) =
569 paras [ line "No type class instance was found for"
564 paras [ line "No type class instance was found for"
570 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
565 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
@@ -587,7 +582,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
587 renderSimpleErrorMessage (CannotFindDerivingType nm) =
582 renderSimpleErrorMessage (CannotFindDerivingType nm) =
588 line $ "Cannot derive a type class instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
583 line $ "Cannot derive a type class instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
589 renderSimpleErrorMessage (DuplicateLabel l expr) =
584 renderSimpleErrorMessage (DuplicateLabel l expr) =
590− paras $ [ line $ "The duplicate label " ++ show l ++ " appears in a row type." ]
585+ paras $ [ line $ "The label " ++ show l ++ " appears more than once in a row type." ]
591 <> foldMap (\expr' -> [ line "Relevant expression: "
586 <> foldMap (\expr' -> [ line "Relevant expression: "
592 , indent $ prettyPrintValue expr'
587 , indent $ prettyPrintValue expr'
@@ -622,7 +617,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
622 renderSimpleErrorMessage (PropertyIsMissing prop row) =
617 renderSimpleErrorMessage (PropertyIsMissing prop row) =
623 paras [ line "The row type"
618 paras [ line "The row type"
624 , indent $ prettyPrintRowWith '(' ')' row
619 , indent $ prettyPrintRowWith '(' ')' row
625− , line $ "lacks the required property " ++ show prop
620+ , line $ "lacks the required label " ++ show prop
627 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
622 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
628 paras [ line "A function of type"
623 paras [ line "A function of type"
@@ -641,11 +636,14 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
641 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
636 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
642 , line "Consider moving the instance, if possible, or using a newtype wrapper."
637 , line "Consider moving the instance, if possible, or using a newtype wrapper."
644− renderSimpleErrorMessage InvalidNewtype =
639+ renderSimpleErrorMessage (InvalidNewtype name) =
640+ paras [ line $ "The newtype " ++ runProperName name ++ " is invalid."
645− line "Newtypes must define a single constructor with a single argument."
641+ , line "Newtypes must define a single constructor with a single argument."
646 renderSimpleErrorMessage (InvalidInstanceHead ty) =
643 renderSimpleErrorMessage (InvalidInstanceHead ty) =
647− paras [ line "An invalid type appears in a type class instance head:"
644+ paras [ line "Type class instance head is invalid due to the use of the type"
648 , indent $ typeAsBox ty
645 , indent $ typeAsBox ty
646+ , 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."
650 renderSimpleErrorMessage (TransitiveExportError x ys) =
648 renderSimpleErrorMessage (TransitiveExportError x ys) =
651 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
649 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
@@ -697,9 +695,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
697 renderHint (NotYetDefined names) =
695 renderHint (NotYetDefined names) =
698 line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
696 line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
699 renderHint (ErrorUnifyingTypes t1 t2) =
697 renderHint (ErrorUnifyingTypes t1 t2) =
700− paras [ lineWithLevel "while trying to make the type "
698+ paras [ lineWithLevel "while trying to match the type "
701 , indent $ typeAsBox t1
699 , indent $ typeAsBox t1
702− , line "equal to the type"
700+ , line "with the type"
703 , indent $ typeAsBox t2
701 , indent $ typeAsBox t2
705 renderHint (ErrorInExpression expr) =
703 renderHint (ErrorInExpression expr) =
@@ -712,7 +710,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
712 renderHint (ErrorInSubsumption t1 t2) =
710 renderHint (ErrorInSubsumption t1 t2) =
713 paras [ lineWithLevel "checking that the type"
711 paras [ lineWithLevel "checking that the type"
714 , indent $ typeAsBox t1
712 , indent $ typeAsBox t1
715− , line "is more general than the type"
713+ , line "is at least as general as the type"
716 , indent $ typeAsBox t2
714 , indent $ typeAsBox t2
718 renderHint (ErrorInInstance nm ts) =
716 renderHint (ErrorInInstance nm ts) =