@@ -41,6 +41,7 @@ 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
4546import Language.PureScript.Pretty
4647import Language.PureScript.Types
@@ -105,7 +106,6 @@ data SimpleErrorMessage
105106 | CycleInTypeSynonym (Maybe ProperName)
106107 | CycleInModules [ModuleName]
107108 | NameIsUndefined Ident
108− | NameNotInScope Ident
109109 | UndefinedTypeVariable ProperName
110110 | PartiallyAppliedSynonym (Qualified ProperName)
111111 | EscapedSkolem (Maybe Expr)
@@ -130,7 +130,7 @@ data SimpleErrorMessage
130130 | CannotApplyFunction Type Expr
131131 | TypeSynonymInstance
132132 | OrphanInstance Ident (Qualified ProperName) [Type]
133− | InvalidNewtype
133+ | InvalidNewtype ProperName
134134 | InvalidInstanceHead Type
135135 | TransitiveExportError DeclarationRef [DeclarationRef]
136136 | ShadowedName Ident
@@ -241,7 +241,6 @@ errorCode em = case unwrapErrorMessage em of
241241 CycleInTypeSynonym{} -> "CycleInTypeSynonym"
242242 CycleInModules{} -> "CycleInModules"
243243 NameIsUndefined{} -> "NameIsUndefined"
244− NameNotInScope{} -> "NameNotInScope"
245244 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
246245 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
247246 EscapedSkolem{} -> "EscapedSkolem"
@@ -266,7 +265,7 @@ errorCode em = case unwrapErrorMessage em of
266265 CannotApplyFunction{} -> "CannotApplyFunction"
267266 TypeSynonymInstance -> "TypeSynonymInstance"
268267 OrphanInstance{} -> "OrphanInstance"
269− InvalidNewtype -> "InvalidNewtype"
268+ InvalidNewtype{} -> "InvalidNewtype"
270269 InvalidInstanceHead{} -> "InvalidInstanceHead"
271270 TransitiveExportError{} -> "TransitiveExportError"
272271 ShadowedName{} -> "ShadowedName"
@@ -403,18 +402,13 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
403402 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
404403 paras [ line "Unable to parse foreign module:"
405404 , 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"
408405 ]
409406 renderSimpleErrorMessage (ErrorParsingModule err) =
410407 paras [ line "Unable to parse module: "
411408 , prettyPrintParseError err
412409 ]
413410 renderSimpleErrorMessage (MissingFFIModule mn) =
414− paras [ 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
417− ]
411+ line $ "The foreign module implementation for module " ++ runModuleName mn ++ " is missing."
418412 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
419413 paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ runModuleName mn ++ ": "
420414 , indent . line $ path
@@ -423,8 +417,6 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
423417 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
424418 paras [ line $ "Multiple foreign module implementations have been provided for module " ++ runModuleName mn ++ ": "
425419 , 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"
428420 ]
429421 renderSimpleErrorMessage InvalidDoBind =
430422 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
451443 , indent . paras $ map (line . displaySourceSpan) filenames
452444 ]
453445 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"
455447 renderSimpleErrorMessage (UnknownModule mn) =
456448 line $ "Unknown module " ++ runModuleName mn
457449 renderSimpleErrorMessage (UnknownType name) =
@@ -465,15 +457,21 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
465457 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
466458 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
467459 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."
462+ ]
469463 renderSimpleErrorMessage (UnknownExportType name) =
470464 line $ "Cannot export unknown type " ++ runProperName name
471465 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."
468+ ]
473469 renderSimpleErrorMessage (UnknownExportTypeClass name) =
474470 line $ "Cannot export unknown type class " ++ runProperName name
475471 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."
474+ ]
477475 renderSimpleErrorMessage (UnknownExportValue name) =
478476 line $ "Cannot export unknown value " ++ showIdent name
479477 renderSimpleErrorMessage (UnknownExportModule name) =
@@ -481,7 +479,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
481479 , line "It either does not exist or has not been imported by the current module."
482480 ]
483481 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
485483 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
486484 line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ ", as it has not been declared."
487485 renderSimpleErrorMessage (ConflictingImport nm mn) =
@@ -510,10 +508,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
510508 renderSimpleErrorMessage (DuplicateValueExport nm) =
511509 line $ "Duplicate export declaration for value " ++ showIdent nm
512510 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."
515− , line "You might be able to evaluate this expression lazily, using something like Control.Lazy.fix"
516− ]
511+ line $ "The value of " ++ showIdent nm ++ " is undefined here, so this reference is not allowed."
517512 renderSimpleErrorMessage (CycleInModules mns) =
518513 line $ "There is a cycle in the module dependencies: " ++ intercalate ", " (map runModuleName mns)
519514 renderSimpleErrorMessage (CycleInTypeSynonym name) =
@@ -524,9 +519,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
524519 , line "Consider using a 'newtype' instead."
525520 ]
526521 renderSimpleErrorMessage (NameIsUndefined ident) =
527− line $ "The name " ++ showIdent ident ++ " is undefined."
528− renderSimpleErrorMessage (NameNotInScope ident) =
529− line $ "The name " ++ showIdent ident ++ " may not be defined in the current scope."
522+ line $ "The value " ++ showIdent ident ++ " is undefined."
530523 renderSimpleErrorMessage (UndefinedTypeVariable name) =
531524 line $ "The type variable " ++ runProperName name ++ " is undefined."
532525 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
@@ -539,21 +532,21 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
539532 , indent $ prettyPrintValue expr
540533 ]) binding
541534 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
542− = paras [ line "The type"
535+ = paras [ line "Could not match expected type"
543536 , indent $ typeAsBox t1
544− , line "cannot be made equal to the type"
537+ , line "with actual type"
545538 , indent $ typeAsBox t2
546539 ]
547540 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
548− paras [ line "The kind"
541+ paras [ line "Could not match expected kind"
549542 , indent $ line $ prettyPrintKind k1
550− , line "cannot be made equal to the kind"
543+ , line "with actual kind"
551544 , indent $ line $ prettyPrintKind k2
552545 ]
553546 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
554− paras [ line "The constrained type"
547+ paras [ line "Could not match the constrained type"
555548 , indent $ typeAsBox t1
556− , line "cannot be made equal to the kind"
549+ , line "with type"
557550 , indent $ typeAsBox t2
558551 ]
559552 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
@@ -563,8 +556,10 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
563556 ]
564557 , line "The following instances were found:"
565558 , 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."
566561 ]
567− renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
562+ renderSimpleErrorMessage OverlappingInstances{} = internalError "OverlappingInstances: empty instance list"
568563 renderSimpleErrorMessage (NoInstanceFound nm ts) =
569564 paras [ line "No type class instance was found for"
570565 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
@@ -587,7 +582,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
587582 renderSimpleErrorMessage (CannotFindDerivingType nm) =
588583 line $ "Cannot derive a type class instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
589584 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." ]
591586 <> foldMap (\expr' -> [ line "Relevant expression: "
592587 , indent $ prettyPrintValue expr'
593588 ]) expr
@@ -622,7 +617,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
622617 renderSimpleErrorMessage (PropertyIsMissing prop row) =
623618 paras [ line "The row type"
624619 , indent $ prettyPrintRowWith '(' ')' row
625− , line $ "lacks the required property " ++ show prop
620+ , line $ "lacks the required label " ++ show prop
626621 ]
627622 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
628623 paras [ line "A function of type"
@@ -641,11 +636,14 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
641636 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
642637 , line "Consider moving the instance, if possible, or using a newtype wrapper."
643638 ]
644− renderSimpleErrorMessage InvalidNewtype =
645− line "Newtypes must define a single constructor with a single argument."
639+ renderSimpleErrorMessage (InvalidNewtype name) =
640+ paras [ line $ "The newtype " ++ runProperName name ++ " is invalid."
641+ , line "Newtypes must define a single constructor with a single argument."
642+ ]
646643 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"
648645 , 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."
649647 ]
650648 renderSimpleErrorMessage (TransitiveExportError x ys) =
651649 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
@@ -697,9 +695,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
697695 renderHint (NotYetDefined names) =
698696 line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
699697 renderHint (ErrorUnifyingTypes t1 t2) =
700− paras [ lineWithLevel "while trying to make the type "
698+ paras [ lineWithLevel "while trying to match the type "
701699 , indent $ typeAsBox t1
702− , line "equal to the type"
700+ , line "with the type"
703701 , indent $ typeAsBox t2
704702 ]
705703 renderHint (ErrorInExpression expr) =
@@ -712,7 +710,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
712710 renderHint (ErrorInSubsumption t1 t2) =
713711 paras [ lineWithLevel "checking that the type"
714712 , indent $ typeAsBox t1
715− , line "is more general than the type"
713+ , line "is at least as general as the type"
716714 , indent $ typeAsBox t2
717715 ]
718716 renderHint (ErrorInInstance nm ts) =