git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Friendlier errors
00a4705Phil Freeman
src/Language/PureScript/Errors.hs+102−106
@@ -42,7 +42,6 @@ import Control.Monad.Trans.State.Lazy
42import Control.Arrow(first)
42import Control.Arrow(first)
43
43
44import Language.PureScript.AST
44import Language.PureScript.AST
45−import Language.PureScript.Environment (isObject, isFunction)
46import Language.PureScript.Pretty
45import Language.PureScript.Pretty
47import Language.PureScript.Types
46import Language.PureScript.Types
48import Language.PureScript.Names
47import Language.PureScript.Names
@@ -62,13 +61,11 @@ data SimpleErrorMessage
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
@@ -112,7 +109,6 @@ data SimpleErrorMessage
112 | UndefinedTypeVariable ProperName
109 | UndefinedTypeVariable ProperName
113 | PartiallyAppliedSynonym (Qualified ProperName)
110 | PartiallyAppliedSynonym (Qualified ProperName)
114 | EscapedSkolem (Maybe Expr)
111 | EscapedSkolem (Maybe Expr)
115− | UnspecifiedSkolemScope
116 | TypesDoNotUnify Type Type
112 | TypesDoNotUnify Type Type
117 | KindsDoNotUnify Kind Kind
113 | KindsDoNotUnify Kind Kind
118 | ConstrainedTypeUnified Type Type
114 | ConstrainedTypeUnified Type Type
@@ -126,10 +122,9 @@ data SimpleErrorMessage
126 | ArgListLengthsDiffer Ident
122 | ArgListLengthsDiffer Ident
127 | OverlappingArgNames (Maybe Ident)
123 | OverlappingArgNames (Maybe Ident)
128 | MissingClassMember Ident
124 | MissingClassMember Ident
129− | ExtraneousClassMember Ident
125+ | ExtraneousClassMember Ident (Qualified ProperName)
130 | ExpectedType Type Kind
126 | ExpectedType Type Kind
131 | IncorrectConstructorArity (Qualified ProperName)
127 | IncorrectConstructorArity (Qualified ProperName)
132− | SubsumptionCheckFailed
133 | ExprDoesNotHaveType Expr Type
128 | ExprDoesNotHaveType Expr Type
134 | PropertyIsMissing String Type
129 | PropertyIsMissing String Type
135 | CannotApplyFunction Type Expr
130 | CannotApplyFunction Type Expr
@@ -202,13 +197,11 @@ errorCode em = case unwrapErrorMessage em of
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"
@@ -252,7 +245,6 @@ errorCode em = case unwrapErrorMessage em of
252 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
245 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
253 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
246 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
254 EscapedSkolem{} -> "EscapedSkolem"
247 EscapedSkolem{} -> "EscapedSkolem"
255− UnspecifiedSkolemScope -> "UnspecifiedSkolemScope"
256 TypesDoNotUnify{} -> "TypesDoNotUnify"
248 TypesDoNotUnify{} -> "TypesDoNotUnify"
257 KindsDoNotUnify{} -> "KindsDoNotUnify"
249 KindsDoNotUnify{} -> "KindsDoNotUnify"
258 ConstrainedTypeUnified{} -> "ConstrainedTypeUnified"
250 ConstrainedTypeUnified{} -> "ConstrainedTypeUnified"
@@ -269,7 +261,6 @@ errorCode em = case unwrapErrorMessage em of
269 ExtraneousClassMember{} -> "ExtraneousClassMember"
261 ExtraneousClassMember{} -> "ExtraneousClassMember"
270 ExpectedType{} -> "ExpectedType"
262 ExpectedType{} -> "ExpectedType"
271 IncorrectConstructorArity{} -> "IncorrectConstructorArity"
263 IncorrectConstructorArity{} -> "IncorrectConstructorArity"
272− SubsumptionCheckFailed -> "SubsumptionCheckFailed"
273 ExprDoesNotHaveType{} -> "ExprDoesNotHaveType"
264 ExprDoesNotHaveType{} -> "ExprDoesNotHaveType"
274 PropertyIsMissing{} -> "PropertyIsMissing"
265 PropertyIsMissing{} -> "PropertyIsMissing"
275 CannotApplyFunction{} -> "CannotApplyFunction"
266 CannotApplyFunction{} -> "CannotApplyFunction"
@@ -385,9 +376,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
385 prettyPrintErrorMessage (ErrorMessage hints simple) =
376 prettyPrintErrorMessage (ErrorMessage hints simple) =
386 paras $
377 paras $
387 map renderHint hints ++
378 map renderHint hints ++
388− renderSimpleErrorMessage simple :
379+ [ renderSimpleErrorMessage simple
389− suggestions simple ++
390− [line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."]
380+ , line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."
381+ ]
391 where
382 where
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
@@ -410,37 +401,37 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
410 , prettyPrintParseError err
401 , prettyPrintParseError err
411 ]
402 ]
412 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
403 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
413− paras [ line "Unable to parse module from FFI file: "
404+ paras [ line "Unable to parse foreign module:"
414 , indent . line $ path
405 , 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"
415 ]
408 ]
416 renderSimpleErrorMessage (ErrorParsingModule err) =
409 renderSimpleErrorMessage (ErrorParsingModule err) =
417 paras [ line "Unable to parse module: "
410 paras [ line "Unable to parse module: "
418 , prettyPrintParseError err
411 , prettyPrintParseError err
419 ]
412 ]
420 renderSimpleErrorMessage (MissingFFIModule mn) =
413 renderSimpleErrorMessage (MissingFFIModule mn) =
421− line $ "Missing FFI implementations for module " ++ runModuleName mn
414+ paras [ line $ "Missing foreign module implementation for module " ++ runModuleName mn
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+ ]
422 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
418 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
423− paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
419+ paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ runModuleName mn ++ ": "
424 , indent . line $ path
420 , indent . line $ path
421+ , line $ "Module " ++ runModuleName mn ++ " does not contain any foreign import declarations, so a foreign module is not necessary."
425 ]
422 ]
426 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
423 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
427− paras [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
424+ paras [ line $ "Multiple foreign module implementations have been provided for module " ++ runModuleName mn ++ ": "
428 , indent . paras $ map line paths
425 , indent . paras $ map line paths
429− ]
426+ , line "Foreign modules are identified by a unique module name, as follows:"
430− renderSimpleErrorMessage (InvalidExternsFile path) =
427+ , indent $ line "// module A.B.C"
431− paras [ line "Externs file is invalid: "
432− , indent . line $ path
433 ]
428 ]
434 renderSimpleErrorMessage InvalidDoBind =
429 renderSimpleErrorMessage InvalidDoBind =
435− line "Bind statement cannot be the last statement in a do block. The last statement must be an expression."
430+ line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
436 renderSimpleErrorMessage InvalidDoLet =
431 renderSimpleErrorMessage InvalidDoLet =
437− line "Let statement cannot be the last statement in a do block. The last statement must be an expression."
432+ 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 =
433 renderSimpleErrorMessage OverlappingNamesInLet =
443− line "Overlapping names in let binding."
434+ line "The same name was used more than once in a let binding."
444 renderSimpleErrorMessage (InfiniteType ty) =
435 renderSimpleErrorMessage (InfiniteType ty) =
445 paras [ line "An infinite type was inferred for an expression: "
436 paras [ line "An infinite type was inferred for an expression: "
446 , indent $ typeAsBox ty
437 , indent $ typeAsBox ty
@@ -450,17 +441,17 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
450 , indent $ line $ prettyPrintKind ki
441 , indent $ line $ prettyPrintKind ki
451 ]
442 ]
452 renderSimpleErrorMessage (MultipleFixities name) =
443 renderSimpleErrorMessage (MultipleFixities name) =
453− line $ "Multiple fixity declarations for " ++ showIdent name
444+ line $ "There are multiple fixity/precedence declarations for " ++ showIdent name
454 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
445 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
455− line $ "Orphan type declaration for " ++ showIdent nm
446+ line $ "The type declaration for " ++ showIdent nm ++ " should be followed by its definition."
456 renderSimpleErrorMessage (OrphanFixityDeclaration op) =
447 renderSimpleErrorMessage (OrphanFixityDeclaration op) =
457− line $ "Orphan fixity declaration for " ++ show op
448+ line $ "The fixity/precedence declaration for " ++ show op ++ " should appear in the same module as its definition."
458 renderSimpleErrorMessage (RedefinedModule name filenames) =
449 renderSimpleErrorMessage (RedefinedModule name filenames) =
459− paras [ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
450+ paras [ line ("The module " ++ runModuleName name ++ " has been defined multiple times:")
460 , indent . paras $ map (line . displaySourceSpan) filenames
451 , indent . paras $ map (line . displaySourceSpan) filenames
461 ]
452 ]
462 renderSimpleErrorMessage (RedefinedIdent name) =
453 renderSimpleErrorMessage (RedefinedIdent name) =
463− line $ "Name " ++ showIdent name ++ " has been defined multiple times"
454+ line $ "The name " ++ showIdent name ++ " has been defined multiple times"
464 renderSimpleErrorMessage (UnknownModule mn) =
455 renderSimpleErrorMessage (UnknownModule mn) =
465 line $ "Unknown module " ++ runModuleName mn
456 line $ "Unknown module " ++ runModuleName mn
466 renderSimpleErrorMessage (UnknownType name) =
457 renderSimpleErrorMessage (UnknownType name) =
@@ -474,25 +465,30 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
474 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
465 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
475 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
466 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
476 renderSimpleErrorMessage (UnknownImportType mn name) =
467 renderSimpleErrorMessage (UnknownImportType mn name) =
477− line $ "Module " ++ runModuleName mn ++ " does not export type " ++ runProperName name
468+ line $ "The type " ++ runProperName name ++ " is not exported by the module " ++ runModuleName mn
478 renderSimpleErrorMessage (UnknownExportType name) =
469 renderSimpleErrorMessage (UnknownExportType name) =
479 line $ "Cannot export unknown type " ++ runProperName name
470 line $ "Cannot export unknown type " ++ runProperName name
480 renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
471 renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
481− line $ "Module " ++ runModuleName mn ++ " does not export type class " ++ runProperName name
472+ line $ "The type class " ++ runProperName name ++ " is not exported by the module " ++ runModuleName mn
482 renderSimpleErrorMessage (UnknownExportTypeClass name) =
473 renderSimpleErrorMessage (UnknownExportTypeClass name) =
483 line $ "Cannot export unknown type class " ++ runProperName name
474 line $ "Cannot export unknown type class " ++ runProperName name
484 renderSimpleErrorMessage (UnknownImportValue mn name) =
475 renderSimpleErrorMessage (UnknownImportValue mn name) =
485− line $ "Module " ++ runModuleName mn ++ " does not export value " ++ showIdent name
476+ line $ "The value " ++ showIdent name ++ " is not exported by the module " ++ runModuleName mn
486 renderSimpleErrorMessage (UnknownExportValue name) =
477 renderSimpleErrorMessage (UnknownExportValue name) =
487 line $ "Cannot export unknown value " ++ showIdent name
478 line $ "Cannot export unknown value " ++ showIdent name
488 renderSimpleErrorMessage (UnknownExportModule name) =
479 renderSimpleErrorMessage (UnknownExportModule name) =
480+ 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"
481+ , line "It either does not exist or has not been imported by the current module."
482+ ]
490 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
483 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
491− line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
484+ line $ "The data constructor " ++ runProperName dcon ++ " (for type " ++ runProperName tcon ++ ") is not exported by the module " ++ runModuleName mn
492 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
485 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
493− line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ " as it has not been declared"
486+ line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ ", as it has not been declared."
494 renderSimpleErrorMessage (ConflictingImport nm mn) =
487 renderSimpleErrorMessage (ConflictingImport nm mn) =
495− line $ "Cannot declare " ++ show nm ++ " since another declaration of that name was imported from " ++ runModuleName mn
488+ paras [ line $ "Cannot declare " ++ show nm ++ ", since another declaration of that name was imported from the module " ++ runModuleName mn
489+ , line $ "Consider hiding " ++ show nm ++ " when importing " ++ runModuleName mn ++ ":"
490+ , indent . line $ "import " ++ runModuleName mn ++ " hiding (" ++ nm ++ ")"
491+ ]
496 renderSimpleErrorMessage (ConflictingImports nm m1 m2) =
492 renderSimpleErrorMessage (ConflictingImports nm m1 m2) =
497 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
493 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
498 renderSimpleErrorMessage (ConflictingTypeDecls nm) =
494 renderSimpleErrorMessage (ConflictingTypeDecls nm) =
@@ -500,33 +496,41 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
500 renderSimpleErrorMessage (ConflictingCtorDecls nm) =
496 renderSimpleErrorMessage (ConflictingCtorDecls nm) =
501 line $ "Conflicting data constructor declarations for " ++ runProperName nm
497 line $ "Conflicting data constructor declarations for " ++ runProperName nm
502 renderSimpleErrorMessage (TypeConflictsWithClass nm) =
498 renderSimpleErrorMessage (TypeConflictsWithClass nm) =
503− line $ "Type " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
499+ line $ "The type " ++ runProperName nm ++ " conflicts with type class declaration of the same name."
504 renderSimpleErrorMessage (CtorConflictsWithClass nm) =
500 renderSimpleErrorMessage (CtorConflictsWithClass nm) =
505− line $ "Data constructor " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
501+ line $ "The data constructor " ++ runProperName nm ++ " conflicts with type class declaration of the same name."
506 renderSimpleErrorMessage (ClassConflictsWithType nm) =
502 renderSimpleErrorMessage (ClassConflictsWithType nm) =
507− line $ "Type class " ++ runProperName nm ++ " conflicts with type declaration of the same name"
503+ line $ "The type class " ++ runProperName nm ++ " conflicts with type declaration of the same name."
508 renderSimpleErrorMessage (ClassConflictsWithCtor nm) =
504 renderSimpleErrorMessage (ClassConflictsWithCtor nm) =
509− line $ "Type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name"
505+ line $ "The type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name."
510 renderSimpleErrorMessage (DuplicateModuleName mn) =
506 renderSimpleErrorMessage (DuplicateModuleName mn) =
511− line $ "Module " ++ runModuleName mn ++ " has been defined multiple times."
507+ line $ "The module " ++ runModuleName mn ++ " has been defined multiple times."
512 renderSimpleErrorMessage (DuplicateClassExport nm) =
508 renderSimpleErrorMessage (DuplicateClassExport nm) =
513 line $ "Duplicate export declaration for type class " ++ runProperName nm
509 line $ "Duplicate export declaration for type class " ++ runProperName nm
514 renderSimpleErrorMessage (DuplicateValueExport nm) =
510 renderSimpleErrorMessage (DuplicateValueExport nm) =
515 line $ "Duplicate export declaration for value " ++ showIdent nm
511 line $ "Duplicate export declaration for value " ++ showIdent nm
516 renderSimpleErrorMessage (CycleInDeclaration nm) =
512 renderSimpleErrorMessage (CycleInDeclaration nm) =
517− line $ "Cycle in declaration of " ++ showIdent 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+ ]
518 renderSimpleErrorMessage (CycleInModules mns) =
517 renderSimpleErrorMessage (CycleInModules mns) =
519− line $ "Cycle in module dependencies: " ++ intercalate ", " (map runModuleName mns)
518+ line $ "There is a cycle in the module dependencies: " ++ intercalate ", " (map runModuleName mns)
520− renderSimpleErrorMessage (CycleInTypeSynonym pn) =
519+ renderSimpleErrorMessage (CycleInTypeSynonym name) =
521− line $ "Cycle in type synonym" ++ foldMap ((" " ++) . runProperName) pn
520+ paras [ line $ case name of
521+ Just pn -> "A cycle appears in the definition of the type synonym " ++ runProperName pn
522+ Nothing -> "A cycle appears in a set of type synonym definitions."
523+ , line "Cycles are disallowed because they can lead to loops in the type checker."
524+ , line "Consider using a 'newtype' instead."
525+ ]
522 renderSimpleErrorMessage (NameIsUndefined ident) =
526 renderSimpleErrorMessage (NameIsUndefined ident) =
523− line $ showIdent ident ++ " is undefined"
527+ line $ "The name " ++ showIdent ident ++ " is undefined."
524 renderSimpleErrorMessage (NameNotInScope ident) =
528 renderSimpleErrorMessage (NameNotInScope ident) =
525− line $ showIdent ident ++ " may not be defined in the current scope"
529+ line $ "The name " ++ showIdent ident ++ " may not be defined in the current scope."
526 renderSimpleErrorMessage (UndefinedTypeVariable name) =
530 renderSimpleErrorMessage (UndefinedTypeVariable name) =
527− line $ "Type variable " ++ runProperName name ++ " is undefined"
531+ line $ "The type variable " ++ runProperName name ++ " is undefined."
528 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
532 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
529− paras [ line $ "Partially applied type synonym " ++ showQualified runProperName name
533+ paras [ line $ "The type synonym " ++ showQualified runProperName name ++ " is partially applied."
530 , line "Type synonyms must be applied to all of their type arguments."
534 , line "Type synonyms must be applied to all of their type arguments."
531 ]
535 ]
532 renderSimpleErrorMessage (EscapedSkolem binding) =
536 renderSimpleErrorMessage (EscapedSkolem binding) =
@@ -535,25 +539,25 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
535 , indent $ prettyPrintValue expr
539 , indent $ prettyPrintValue expr
536 ]) binding
540 ]) binding
537 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
541 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
538− = paras [ line "Cannot unify type"
542+ = paras [ line "The type"
539 , indent $ typeAsBox t1
543 , indent $ typeAsBox t1
540− , line "with type"
544+ , line "cannot be made equal to the type"
541 , indent $ typeAsBox t2
545 , indent $ typeAsBox t2
542 ]
546 ]
543 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
547 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
544− paras [ line "Cannot unify kind"
548+ paras [ line "The kind"
545 , indent $ line $ prettyPrintKind k1
549 , indent $ line $ prettyPrintKind k1
546− , line "with kind"
550+ , line "cannot be made equal to the kind"
547 , indent $ line $ prettyPrintKind k2
551 , indent $ line $ prettyPrintKind k2
548 ]
552 ]
549 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
553 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
550− paras [ line "Cannot unify constrained type"
554+ paras [ line "The constrained type"
551 , indent $ typeAsBox t1
555 , indent $ typeAsBox t1
552− , line "with type"
556+ , line "cannot be made equal to the kind"
553 , indent $ typeAsBox t2
557 , indent $ typeAsBox t2
554 ]
558 ]
555 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
559 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
556− paras [ line "Overlapping instances found for"
560+ paras [ line "Overlapping type class instances found for"
557 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
561 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
558 , Box.vcat Box.left (map typeAtomAsBox ts)
562 , Box.vcat Box.left (map typeAtomAsBox ts)
559 ]
563 ]
@@ -562,43 +566,43 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
562 ]
566 ]
563 renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
567 renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
564 renderSimpleErrorMessage (NoInstanceFound nm ts) =
568 renderSimpleErrorMessage (NoInstanceFound nm ts) =
565− paras [ line "No instance found for"
569+ paras [ line "No type class instance was found for"
566 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
570 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
567 , Box.vcat Box.left (map typeAtomAsBox ts)
571 , Box.vcat Box.left (map typeAtomAsBox ts)
568 ]
572 ]
569 ]
573 ]
570 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
574 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
571− paras [ line "Instance for"
575+ paras [ line "The type class instance for"
572 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
576 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
573 , Box.vcat Box.left (map typeAtomAsBox ts)
577 , Box.vcat Box.left (map typeAtomAsBox ts)
574 ]
578 ]
575 , line "is possibly infinite."
579 , line "is possibly infinite."
576 ]
580 ]
577 renderSimpleErrorMessage (CannotDerive nm ts) =
581 renderSimpleErrorMessage (CannotDerive nm ts) =
578− paras [ line "Cannot derive an instance for"
582+ paras [ line "Cannot derive a type class instance for"
579 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
583 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
580 , Box.vcat Box.left (map typeAtomAsBox ts)
584 , Box.vcat Box.left (map typeAtomAsBox ts)
581 ]
585 ]
582 ]
586 ]
583 renderSimpleErrorMessage (CannotFindDerivingType nm) =
587 renderSimpleErrorMessage (CannotFindDerivingType nm) =
584− line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
588+ line $ "Cannot derive a type class instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
585 renderSimpleErrorMessage (DuplicateLabel l expr) =
589 renderSimpleErrorMessage (DuplicateLabel l expr) =
586− paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
590+ paras $ [ line $ "The duplicate label " ++ show l ++ " appears in a row type." ]
587 <> foldMap (\expr' -> [ line "Relevant expression: "
591 <> foldMap (\expr' -> [ line "Relevant expression: "
588 , indent $ prettyPrintValue expr'
592 , indent $ prettyPrintValue expr'
589 ]) expr
593 ]) expr
590 renderSimpleErrorMessage (DuplicateTypeArgument name) =
594 renderSimpleErrorMessage (DuplicateTypeArgument name) =
591− line $ "Duplicate type argument " ++ show name
595+ line $ "The type argument " ++ show name ++ " appears more than once."
592 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
596 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
593− line $ "Duplicate value declaration for " ++ showIdent nm
597+ line $ "Multiple value declarations exist for " ++ showIdent nm ++ "."
594 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
598 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
595 line $ "Argument list lengths differ in declaration " ++ showIdent ident
599 line $ "Argument list lengths differ in declaration " ++ showIdent ident
596 renderSimpleErrorMessage (OverlappingArgNames ident) =
600 renderSimpleErrorMessage (OverlappingArgNames ident) =
597 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
601 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
598 renderSimpleErrorMessage (MissingClassMember ident) =
602 renderSimpleErrorMessage (MissingClassMember ident) =
599− line $ "Member " ++ showIdent ident ++ " has not been implemented"
603+ line $ "The type class member " ++ showIdent ident ++ " has not been implemented."
600− renderSimpleErrorMessage (ExtraneousClassMember ident) =
604+ renderSimpleErrorMessage (ExtraneousClassMember ident className) =
601− line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
605+ line $ showIdent ident ++ " is not a member of type class " ++ showQualified runProperName className
602 renderSimpleErrorMessage (ExpectedType ty kind) =
606 renderSimpleErrorMessage (ExpectedType ty kind) =
603 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
607 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
604 , line "The error arises from the type"
608 , line "The error arises from the type"
@@ -608,29 +612,28 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
608 , line "instead."
612 , line "instead."
609 ]
613 ]
610 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
614 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
611− line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
615+ line $ "The 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) =
616 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
614− paras [ line "Expression"
617+ paras [ line "The expression"
615 , indent $ prettyPrintValue expr
618 , indent $ prettyPrintValue expr
616 , line "does not have type"
619 , line "does not have type"
617 , indent $ typeAsBox ty
620 , indent $ typeAsBox ty
618 ]
621 ]
619 renderSimpleErrorMessage (PropertyIsMissing prop row) =
622 renderSimpleErrorMessage (PropertyIsMissing prop row) =
620− paras [ line "Row"
623+ paras [ line "The row type"
621 , indent $ prettyPrintRowWith '(' ')' row
624 , indent $ prettyPrintRowWith '(' ')' row
622− , line $ "lacks required property " ++ show prop
625+ , line $ "lacks the required property " ++ show prop
623 ]
626 ]
624 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
627 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
625− paras [ line "Cannot apply function of type"
628+ paras [ line "A function of type"
626 , indent $ typeAsBox fn
629 , indent $ typeAsBox fn
627− , line "to argument"
630+ , line "can not be applied to the argument"
628 , indent $ prettyPrintValue arg
631 , indent $ prettyPrintValue arg
629 ]
632 ]
630 renderSimpleErrorMessage TypeSynonymInstance =
633 renderSimpleErrorMessage TypeSynonymInstance =
631− line "Type synonym instances are disallowed"
634+ line "Type class instances for type synonyms are disallowed."
632 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
635 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
633− paras [ line $ "Instance " ++ showIdent nm ++ " for "
636+ paras [ line $ "The type class instance " ++ showIdent nm ++ " for "
634 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
637 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
635 , Box.vcat Box.left (map typeAtomAsBox ts)
638 , Box.vcat Box.left (map typeAtomAsBox ts)
636 ]
639 ]
@@ -639,29 +642,31 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
639 , line "Consider moving the instance, if possible, or using a newtype wrapper."
642 , line "Consider moving the instance, if possible, or using a newtype wrapper."
640 ]
643 ]
641 renderSimpleErrorMessage InvalidNewtype =
644 renderSimpleErrorMessage InvalidNewtype =
642− line "Newtypes must define a single constructor with a single argument"
645+ line "Newtypes must define a single constructor with a single argument."
643 renderSimpleErrorMessage (InvalidInstanceHead ty) =
646 renderSimpleErrorMessage (InvalidInstanceHead ty) =
644− paras [ line "Invalid type in class instance head:"
647+ paras [ line "An invalid type appears in a type class instance head:"
645 , indent $ typeAsBox ty
648 , indent $ typeAsBox ty
646 ]
649 ]
647 renderSimpleErrorMessage (TransitiveExportError x ys) =
650 renderSimpleErrorMessage (TransitiveExportError x ys) =
648 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
651 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
649 : map (line . prettyPrintExport) ys
652 : map (line . prettyPrintExport) ys
650 renderSimpleErrorMessage (ShadowedName nm) =
653 renderSimpleErrorMessage (ShadowedName nm) =
651− line $ "Name '" ++ showIdent nm ++ "' was shadowed"
654+ line $ "The name '" ++ showIdent nm ++ "' was shadowed."
652 renderSimpleErrorMessage (ShadowedTypeVar tv) =
655 renderSimpleErrorMessage (ShadowedTypeVar tv) =
653− line $ "Type variable '" ++ tv ++ "' was shadowed"
656+ line $ "The type variable '" ++ tv ++ "' was shadowed."
654 renderSimpleErrorMessage (UnusedTypeVar tv) =
657 renderSimpleErrorMessage (UnusedTypeVar tv) =
655− line $ "Type variable '" ++ tv ++ "' was declared but not used"
658+ line $ "The type variable '" ++ tv ++ "' was declared but not used."
656 renderSimpleErrorMessage (ClassOperator className opName) =
659 renderSimpleErrorMessage (ClassOperator className opName) =
657− paras [ line $ "Class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
660+ paras [ line $ "The 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:"
661 , 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"
662 , indent . line $ showIdent opName ++ " = someMember"
660 ]
663 ]
661 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
664 renderSimpleErrorMessage (MisleadingEmptyTypeImport mn name) =
662− line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors"
665+ line $ "Importing type " ++ runProperName name ++ "(..) from " ++ runModuleName mn ++ " is misleading as it has no exported data constructors."
663 renderSimpleErrorMessage (ImportHidingModule name) =
666 renderSimpleErrorMessage (ImportHidingModule name) =
667+ 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"
668+ , line $ "An attempt was made to hide the import of " ++ runModuleName name
669+ ]
665 renderSimpleErrorMessage (WildcardInferredType ty) =
670 renderSimpleErrorMessage (WildcardInferredType ty) =
666 paras [ line "The wildcard type definition has the inferred type "
671 paras [ line "The wildcard type definition has the inferred type "
667 , indent $ typeAsBox ty
672 , indent $ typeAsBox ty
@@ -692,9 +697,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
692 renderHint (NotYetDefined names) =
697 renderHint (NotYetDefined names) =
693 line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
698 line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
694 renderHint (ErrorUnifyingTypes t1 t2) =
699 renderHint (ErrorUnifyingTypes t1 t2) =
695− paras [ lineWithLevel "unifying type "
700+ paras [ lineWithLevel "while trying to make the type "
696 , indent $ typeAsBox t1
701 , indent $ typeAsBox t1
697− , line "with type"
702+ , line "equal to the type"
698 , indent $ typeAsBox t2
703 , indent $ typeAsBox t2
699 ]
704 ]
700 renderHint (ErrorInExpression expr) =
705 renderHint (ErrorInExpression expr) =
@@ -705,9 +710,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
705 paras [ lineWithLevel $ "in module " ++ runModuleName mn ++ ":"
710 paras [ lineWithLevel $ "in module " ++ runModuleName mn ++ ":"
706 ]
711 ]
707 renderHint (ErrorInSubsumption t1 t2) =
712 renderHint (ErrorInSubsumption t1 t2) =
708− paras [ lineWithLevel "checking that type "
713+ paras [ lineWithLevel "checking that the type"
709 , indent $ typeAsBox t1
714 , indent $ typeAsBox t1
710− , line "subsumes type"
715+ , line "is more general than the type"
711 , indent $ typeAsBox t2
716 , indent $ typeAsBox t2
712 ]
717 ]
713 renderHint (ErrorInInstance nm ts) =
718 renderHint (ErrorInInstance nm ts) =
@@ -717,25 +722,25 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
717 ]
722 ]
718 ]
723 ]
719 renderHint (ErrorCheckingKind ty) =
724 renderHint (ErrorCheckingKind ty) =
720− paras [ lineWithLevel "checking kind of type "
725+ paras [ lineWithLevel "checking the kind of the type"
721 , indent $ typeAsBox ty
726 , indent $ typeAsBox ty
722 ]
727 ]
723 renderHint (ErrorInferringType expr) =
728 renderHint (ErrorInferringType expr) =
724− paras [ lineWithLevel "inferring type of value "
729+ paras [ lineWithLevel "inferring the type of the expression"
725 , indent $ prettyPrintValue expr
730 , indent $ prettyPrintValue expr
726 ]
731 ]
727 renderHint (ErrorCheckingType expr ty) =
732 renderHint (ErrorCheckingType expr ty) =
728− paras [ lineWithLevel "checking that value "
733+ paras [ lineWithLevel "checking that the expression"
729 , indent $ prettyPrintValue expr
734 , indent $ prettyPrintValue expr
730− , line "has type"
735+ , line "has the type"
731 , indent $ typeAsBox ty
736 , indent $ typeAsBox ty
732 ]
737 ]
733 renderHint (ErrorInApplication f t a) =
738 renderHint (ErrorInApplication f t a) =
734− paras [ lineWithLevel "applying function"
739+ paras [ lineWithLevel "applying a function"
735 , indent $ prettyPrintValue f
740 , indent $ prettyPrintValue f
736 , line "of type"
741 , line "of type"
737 , indent $ typeAsBox t
742 , indent $ typeAsBox t
738− , line "to argument"
743+ , line "to the argument"
739 , indent $ prettyPrintValue a
744 , indent $ prettyPrintValue a
740 ]
745 ]
741 renderHint (ErrorInDataConstructor nm) =
746 renderHint (ErrorInDataConstructor nm) =
@@ -765,15 +770,6 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
765 Error -> "error"
770 Error -> "error"
766 Warning -> "warning"
771 Warning -> "warning"
767
772
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−
777 paras :: [Box.Box] -> Box.Box
773 paras :: [Box.Box] -> Box.Box
778 paras = Box.vcat Box.left
774 paras = Box.vcat Box.left
779
775
src/Language/PureScript/Sugar/Operators.hs+1−1
@@ -129,7 +129,7 @@ matchOperators ops = parseChains
129 extendChain (BinaryNoParens op l r) = Left l : Right op : extendChain r
129 extendChain (BinaryNoParens op l r) = Left l : Right op : extendChain r
130 extendChain other = [Left other]
130 extendChain other = [Left other]
131 bracketChain :: Chain -> m Expr
131 bracketChain :: Chain -> m Expr
132− bracketChain = either (const . throwError . errorMessage $ CannotReorderOperators) return . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
132+ bracketChain = either (\_ -> error "matchOperators: cannot reorder operators") return . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
133 opTable = [P.Infix (P.try (parseTicks >>= \op -> return (\t1 t2 -> App (App op t1) t2))) P.AssocLeft]
133 opTable = [P.Infix (P.try (parseTicks >>= \op -> return (\t1 t2 -> App (App op t1) t2))) P.AssocLeft]
134 : map (map (\(name, f, a) -> P.Infix (P.try (matchOp name) >> return f) (toAssoc a))) ops
134 : map (map (\(name, f, a) -> P.Infix (P.try (matchOp name) >> return f) (toAssoc a))) ops
135 ++ [[ P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) t1) t2))) P.AssocLeft ]]
135 ++ [[ P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) t1) t2))) P.AssocLeft ]]
src/Language/PureScript/Sugar/TypeClasses.hs+1−1
@@ -289,7 +289,7 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls =
289
289
290 memberToValue :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [(Ident, Type)] -> Declaration -> Desugar m Expr
290 memberToValue :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [(Ident, Type)] -> Declaration -> Desugar m Expr
291 memberToValue tys' (ValueDeclaration ident _ [] (Right val)) = do
291 memberToValue tys' (ValueDeclaration ident _ [] (Right val)) = do
292− _ <- maybe (throwError . errorMessage $ ExtraneousClassMember ident) return $ lookup ident tys'
292+ _ <- maybe (throwError . errorMessage $ ExtraneousClassMember ident className) return $ lookup ident tys'
293 return val
293 return val
294 memberToValue tys' (PositionedDeclaration pos com d) = rethrowWithPosition pos $ do
294 memberToValue tys' (PositionedDeclaration pos com d) = rethrowWithPosition pos $ do
295 val <- memberToValue tys' d
295 val <- memberToValue tys' d
src/Language/PureScript/TypeChecker/Subsumption.hs+1−1
@@ -50,7 +50,7 @@ subsumes' val ty1 (ForAll ident ty2 sco) =
50 sko <- newSkolemConstant
50 sko <- newSkolemConstant
51 let sk = skolemize ident sko sco' ty2
51 let sk = skolemize ident sko sco' ty2
52 subsumes val ty1 sk
52 subsumes val ty1 sk
53− Nothing -> throwError . errorMessage $ UnspecifiedSkolemScope
53+ Nothing -> error "subsumes: unspecified skolem scope"
54subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
54subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
55 _ <- subsumes Nothing arg2 arg1
55 _ <- subsumes Nothing arg2 arg1
56 _ <- subsumes Nothing ret1 ret2
56 _ <- subsumes Nothing ret1 ret2
src/Language/PureScript/TypeChecker/Types.hs+4−4
@@ -496,7 +496,7 @@ check' v@(Var var) ty = do
496 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
496 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
497 v' <- subsumes (Just v) repl ty'
497 v' <- subsumes (Just v) repl ty'
498 case v' of
498 case v' of
499− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
499+ Nothing -> error "check: unable to check the subsumes relation."
500 Just v'' -> return $ TypedValue True v'' ty'
500 Just v'' -> return $ TypedValue True v'' ty'
501check' (SuperClassDictionary className tys) _ = do
501check' (SuperClassDictionary className tys) _ = do
502 {-
502 {-
@@ -515,7 +515,7 @@ check' (TypedValue checkType val ty1) ty2 = do
515 ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty2
515 ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty2
516 val' <- subsumes (Just val) ty1' ty2'
516 val' <- subsumes (Just val) ty1' ty2'
517 case val' of
517 case val' of
518− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
518+ Nothing -> error "check: unable to check the subsumes relation."
519 Just _ -> do
519 Just _ -> do
520 val''' <- if checkType then withScopedTypeVars moduleName args (check val ty2') else return val
520 val''' <- if checkType then withScopedTypeVars moduleName args (check val ty2') else return val
521 return $ TypedValue checkType val''' ty2'
521 return $ TypedValue checkType val''' ty2'
@@ -557,7 +557,7 @@ check' v@(Constructor c) ty = do
557 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
557 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
558 mv <- subsumes (Just v) repl ty
558 mv <- subsumes (Just v) repl ty
559 case mv of
559 case mv of
560− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
560+ Nothing -> error "check: unable to check the subsumes relation."
561 Just v' -> return $ TypedValue True v' ty
561 Just v' -> return $ TypedValue True v' ty
562check' (Let ds val) ty = do
562check' (Let ds val) ty = do
563 (ds', val') <- inferLetBinding [] ds val (`check` ty)
563 (ds', val') <- inferLetBinding [] ds val (`check` ty)
@@ -572,7 +572,7 @@ check' val ty = do
572 TypedValue _ val' ty' <- infer val
572 TypedValue _ val' ty' <- infer val
573 mt <- subsumes (Just val') ty' ty
573 mt <- subsumes (Just val') ty' ty
574 case mt of
574 case mt of
575− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
575+ Nothing -> error "check: unable to check the subsumes relation."
576 Just v' -> return $ TypedValue True v' ty
576 Just v' -> return $ TypedValue True v' ty
577
577
578-- |
578-- |
src/Language/PureScript/TypeChecker/Unify.hs+2−2
@@ -74,12 +74,12 @@ unifyTypes t1 t2 = rethrow (addHint (ErrorUnifyingTypes t1 t2)) $
74 let sk1 = skolemize ident1 sko sc1' ty1
74 let sk1 = skolemize ident1 sko sc1' ty1
75 let sk2 = skolemize ident2 sko sc2' ty2
75 let sk2 = skolemize ident2 sko sc2' ty2
76 sk1 `unifyTypes` sk2
76 sk1 `unifyTypes` sk2
77− _ -> error "Skolemized type variable was not given a scope"
77+ _ -> error "unifyTypes: unspecified skolem scope"
78 unifyTypes' (ForAll ident ty1 (Just sc)) ty2 = do
78 unifyTypes' (ForAll ident ty1 (Just sc)) ty2 = do
79 sko <- newSkolemConstant
79 sko <- newSkolemConstant
80 let sk = skolemize ident sko sc ty1
80 let sk = skolemize ident sko sc ty1
81 sk `unifyTypes` ty2
81 sk `unifyTypes` ty2
82− unifyTypes' ForAll{} _ = throwError . errorMessage $ UnspecifiedSkolemScope
82+ unifyTypes' ForAll{} _ = error "unifyTypes: unspecified skolem scope"
83 unifyTypes' ty f@ForAll{} = f `unifyTypes` ty
83 unifyTypes' ty f@ForAll{} = f `unifyTypes` ty
84 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
84 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
85 unifyTypes' ty1@(TypeConstructor c1) ty2@(TypeConstructor c2) =
85 unifyTypes' ty1@(TypeConstructor c1) ty2@(TypeConstructor c2) =