git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add internalError, make some of @garyb's suggested changes.
commit688fc66c27cfd4d8505cd11006a9eac6b55e1f31 authorPhil Freeman <paf31@cantab.net> dateSat 24 Oct 2015, 14:42 (11 years ago) parent1059be8
41 files changed+188−144
psci/PSCi.hs+3−3 purescript.cabal+1 src/Language/PureScript.hs+1 src/Language/PureScript/AST/Operators.hs+3−1 src/Language/PureScript/CodeGen/JS.hs+3−2 src/Language/PureScript/CodeGen/JS/Optimizer/Common.hs+2−1 src/Language/PureScript/CoreFn/Desugar.hs+4−3 src/Language/PureScript/Crash.hs+9 src/Language/PureScript/Docs/Convert.hs+1−1 src/Language/PureScript/Docs/RenderedCode/Render.hs+3−2 src/Language/PureScript/Environment.hs+2−1 src/Language/PureScript/Errors.hs+37−39 src/Language/PureScript/Externs.hs+4−3 src/Language/PureScript/Linter.hs+2−1 src/Language/PureScript/Linter/Exhaustive.hs+3−2 src/Language/PureScript/Make.hs+8−7 src/Language/PureScript/ModuleDependencies.hs+2−1 src/Language/PureScript/Pretty/JS.hs+3−2 src/Language/PureScript/Pretty/Kinds.hs+2−1 src/Language/PureScript/Pretty/Types.hs+3−2 src/Language/PureScript/Pretty/Values.hs+2−1 src/Language/PureScript/Sugar/BindingGroups.hs+6−5 src/Language/PureScript/Sugar/CaseDeclarations.hs+3−2 src/Language/PureScript/Sugar/DoNotation.hs+2−1 src/Language/PureScript/Sugar/Names.hs+2−1 src/Language/PureScript/Sugar/Names/Exports.hs+8−7 src/Language/PureScript/Sugar/Names/Imports.hs+7−6 src/Language/PureScript/Sugar/Operators.hs+3−2 src/Language/PureScript/Sugar/TypeClasses.hs+8−7 src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+4−3 src/Language/PureScript/Sugar/TypeDeclarations.hs+2−1 src/Language/PureScript/TypeChecker.hs+14−13 src/Language/PureScript/TypeChecker/Entailment.hs+3−2 src/Language/PureScript/TypeChecker/Kinds.hs+2−1 src/Language/PureScript/TypeChecker/Monad.hs+1−1 src/Language/PureScript/TypeChecker/Skolems.hs+2−1 src/Language/PureScript/TypeChecker/Subsumption.hs+2−1 src/Language/PureScript/TypeChecker/Types.hs+13−12 src/Language/PureScript/TypeChecker/Unify.hs+3−2 tests/Main.hs+2−2 tests/common/TestsSetup.hs+3−1
psci/PSCi.hs+3−3
@@ -71,7 +71,7 @@ supportModule :: P.Module
7171supportModule =
7272 case P.parseModulesFromFiles id [("", code)] of
7373 Right [(_, P.Module ss cs _ ds exps)] -> P.Module ss cs supportModuleName ds exps
74− _ -> error "Support module could not be parsed"
74+ _ -> P.internalError "Support module could not be parsed"
7575 where
7676 code :: String
7777 code = unlines
@@ -390,7 +390,7 @@ printModuleSignatures moduleName env =
390390 findType envNames m@(_, mIdent) = (mIdent, M.lookup m envNames)
391391 showType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> String
392392 showType (mIdent, Just (mType, _, _)) = show mIdent ++ " :: " ++ P.prettyPrintType mType
393− showType _ = error "The impossible happened in printModuleSignatures."
393+ showType _ = P.internalError "The impossible happened in printModuleSignatures."
394394
395395-- |
396396-- Browse a module and displays its signature (if module exists).
@@ -482,7 +482,7 @@ handleCommand (KindOf typ) = handleKindOf typ
482482handleCommand (BrowseModule moduleName) = handleBrowse moduleName
483483handleCommand (ShowInfo QueryLoaded) = handleShowLoadedModules
484484handleCommand (ShowInfo QueryImport) = handleShowImportedModules
485−handleCommand QuitPSCi = error "`handleCommand QuitPSCi` was called. This is a bug."
485+handleCommand QuitPSCi = P.internalError "`handleCommand QuitPSCi` was called. This is a bug."
486486
487487whenFileExists :: FilePath -> (FilePath -> PSCI ()) -> PSCI ()
488488whenFileExists filePath f = do
purescript.cabal+1
@@ -79,6 +79,7 @@ library
7979 Language.PureScript.AST.Traversals
8080 Language.PureScript.AST.Exported
8181 Language.PureScript.Bundle
82+ Language.PureScript.Crash
8283 Language.PureScript.Externs
8384 Language.PureScript.CodeGen
8485 Language.PureScript.CodeGen.JS
src/Language/PureScript.hs+1
@@ -26,6 +26,7 @@ module Language.PureScript
2626import Data.Version (Version)
2727
2828import Language.PureScript.AST as P
29+import Language.PureScript.Crash as P
2930import Language.PureScript.Comments as P
3031import Language.PureScript.Environment as P
3132import Language.PureScript.Errors as P hiding (indent)
src/Language/PureScript/AST/Operators.hs+3−1
@@ -21,6 +21,8 @@ import qualified Data.Data as D
2121import Data.Aeson ((.=))
2222import qualified Data.Aeson as A
2323
24+import Language.PureScript.Crash
25+
2426-- |
2527-- A precedence level for an infix operator
2628--
@@ -40,7 +42,7 @@ readAssoc :: String -> Associativity
4042readAssoc "infixl" = Infixl
4143readAssoc "infixr" = Infixr
4244readAssoc "infix" = Infix
43−readAssoc _ = error "readAssoc: no parse"
45+readAssoc _ = internalError "readAssoc: no parse"
4446
4547instance A.ToJSON Associativity where
4648 toJSON = A.toJSON . showAssoc
src/Language/PureScript/CodeGen/JS.hs+3−2
@@ -38,6 +38,7 @@ import Control.Monad (replicateM, forM)
3838import Control.Monad.Reader (MonadReader, asks)
3939import Control.Monad.Supply.Class
4040
41+import Language.PureScript.Crash
4142import Language.PureScript.AST.SourcePos
4243import Language.PureScript.CodeGen.JS.AST as AST
4344import Language.PureScript.CodeGen.JS.Common as Common
@@ -272,7 +273,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ = do
272273 go (v:vs) done' (b:bs) = do
273274 done'' <- go vs done' bs
274275 binderToJs v done'' b
275− go _ _ _ = error "Invalid arguments to bindersToJs"
276+ go _ _ _ = internalError "Invalid arguments to bindersToJs"
276277
277278 failedPatternError :: [String] -> JS
278279 failedPatternError names = JSUnary JSNew $ JSApp (JSVar "Error") [JSBinary Add (JSStringLiteral errorMessage) (JSArrayLiteral $ zipWith valueError names vals)]
@@ -322,7 +323,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ = do
322323 js <- binderToJs argVar done'' binder
323324 return (JSVariableIntroduction argVar (Just (JSAccessor (identToJs field) (JSVar varName))) : js)
324325 binderToJs _ _ ConstructorBinder{} =
325− error "binderToJs: Invalid ConstructorBinder in binderToJs"
326+ internalError "binderToJs: Invalid ConstructorBinder in binderToJs"
326327 binderToJs varName done (NamedBinder _ ident binder) = do
327328 js <- binderToJs varName done binder
328329 return (JSVariableIntroduction (identToJs ident) (Just (JSVar varName)) : js)
src/Language/PureScript/CodeGen/JS/Optimizer/Common.hs+2−1
@@ -17,6 +17,7 @@ module Language.PureScript.CodeGen.JS.Optimizer.Common where
1717
1818import Data.Maybe (fromMaybe)
1919
20+import Language.PureScript.Crash
2021import Language.PureScript.CodeGen.JS.AST
2122
2223applyAll :: [a -> a] -> a -> a
@@ -63,7 +64,7 @@ targetVariable :: JS -> String
6364targetVariable (JSVar var) = var
6465targetVariable (JSAccessor _ tgt) = targetVariable tgt
6566targetVariable (JSIndexer _ tgt) = targetVariable tgt
66−targetVariable _ = error "Invalid argument to targetVariable"
67+targetVariable _ = internalError "Invalid argument to targetVariable"
6768
6869isUpdated :: String -> JS -> Bool
6970isUpdated var1 = everythingOnJS (||) check
src/Language/PureScript/CoreFn/Desugar.hs+4−3
@@ -21,6 +21,7 @@ import qualified Data.Map as M
2121
2222import Control.Arrow (second, (***))
2323
24+import Language.PureScript.Crash
2425import Language.PureScript.AST.SourcePos
2526import Language.PureScript.AST.Traversals
2627import Language.PureScript.CoreFn.Ann
@@ -41,7 +42,7 @@ import qualified Language.PureScript.AST as A
4142--
4243moduleToCoreFn :: Environment -> A.Module -> Module Ann
4344moduleToCoreFn _ (A.Module _ _ _ _ Nothing) =
44− error "Module exports were not elaborated before moduleToCoreFn"
45+ internalError "Module exports were not elaborated before moduleToCoreFn"
4546moduleToCoreFn env (A.Module _ coms mn decls (Just exps)) =
4647 let imports = nub $ mapMaybe importToCoreFn decls ++ findQualModules decls
4748 exps' = nub $ concatMap exportToCoreFn exps
@@ -98,7 +99,7 @@ moduleToCoreFn env (A.Module _ coms mn decls (Just exps)) =
9899 exprToCoreFn ss com ty (A.Abs (Left name) v) =
99100 Abs (ss, com, ty, Nothing) name (exprToCoreFn ss [] Nothing v)
100101 exprToCoreFn _ _ _ (A.Abs _ _) =
101− error "Abs with Binder argument was not desugared before exprToCoreFn mn"
102+ internalError "Abs with Binder argument was not desugared before exprToCoreFn mn"
102103 exprToCoreFn ss com ty (A.App v1 v2) =
103104 App (ss, com, ty, Nothing) (exprToCoreFn ss [] Nothing v1) (exprToCoreFn ss [] Nothing v2)
104105 exprToCoreFn ss com ty (A.Var ident) =
@@ -193,7 +194,7 @@ moduleToCoreFn env (A.Module _ coms mn decls (Just exps)) =
193194 numConstructors ty = length $ filter (((==) `on` typeConstructor) ty) $ M.toList $ dataConstructors env
194195 typeConstructor :: (Qualified ProperName, (DataDeclType, ProperName, Type, [Ident])) -> (ModuleName, ProperName)
195196 typeConstructor (Qualified (Just mn') _, (_, tyCtor, _, _)) = (mn', tyCtor)
196− typeConstructor _ = error "Invalid argument to typeConstructor"
197+ typeConstructor _ = internalError "Invalid argument to typeConstructor"
197198
198199-- |
199200-- Find module names from qualified references to values. This is used to
src/Language/PureScript/Crash.hsnew file+9
@@ -0,0 +1,9 @@
1+module Language.PureScript.Crash where
2+
3+-- | Exit with an error message and a crash report link.
4+internalError :: String -> a
5+internalError =
6+ error
7+ . ("An internal error ocurred during compilation: " ++)
8+ . (++ "\nPlease report this at https://github.com/purescript/purescript/issues")
9+ . show
src/Language/PureScript/Docs/Convert.hs+1−1
@@ -157,7 +157,7 @@ convertDeclaration (P.TypeClassDeclaration _ args implies ds) title =
157157 convertClassMember (P.TypeDeclaration ident' ty) =
158158 ChildDeclaration (P.showIdent ident') Nothing Nothing (ChildTypeClassMember ty)
159159 convertClassMember _ =
160− error "Invalid argument to convertClassMember."
160+ P.internalError "convertDeclaration: Invalid argument to convertClassMember."
161161convertDeclaration (P.TypeInstanceDeclaration _ constraints className tys _) title =
162162 Just (Left (classNameString : typeNameStrings, AugmentChild childDecl))
163163 where
src/Language/PureScript/Docs/RenderedCode/Render.hs+3−2
@@ -22,6 +22,7 @@ import Data.Maybe (fromMaybe)
2222import Control.Arrow ((<+>))
2323import Control.PatternArrows
2424
25+import Language.PureScript.Crash
2526import Language.PureScript.Names
2627import Language.PureScript.Types
2728import Language.PureScript.Kinds
@@ -163,7 +164,7 @@ renderKind = kind . prettyPrintKind
163164--
164165renderTypeAtom :: Type -> RenderedCode
165166renderTypeAtom =
166− fromMaybe (error "Incomplete pattern") . pattern matchTypeAtom () . preprocessType defaultRenderTypeOptions
167+ fromMaybe (internalError "Incomplete pattern") . pattern matchTypeAtom () . preprocessType defaultRenderTypeOptions
167168
168169
169170-- |
@@ -181,4 +182,4 @@ defaultRenderTypeOptions = RenderTypeOptions { prettyPrintObjects = True }
181182
182183renderTypeWithOptions :: RenderTypeOptions -> Type -> RenderedCode
183184renderTypeWithOptions opts =
184− fromMaybe (error "Incomplete pattern") . pattern matchType () . preprocessType opts
185+ fromMaybe (internalError "Incomplete pattern") . pattern matchType () . preprocessType opts
src/Language/PureScript/Environment.hs+2−1
@@ -25,6 +25,7 @@ import qualified Data.Map as M
2525import qualified Data.Text as T
2626import qualified Data.Aeson as A
2727
28+import Language.PureScript.Crash
2829import Language.PureScript.Kinds
2930import Language.PureScript.Names
3031import Language.PureScript.TypeClassDictionaries
@@ -252,7 +253,7 @@ primTypes = M.fromList [ (primName "Function" , (FunKind Star (FunKind Star Star
252253--
253254lookupConstructor :: Environment -> Qualified ProperName -> (DataDeclType, ProperName, Type, [Ident])
254255lookupConstructor env ctor =
255− fromMaybe (error "Data constructor not found") $ ctor `M.lookup` dataConstructors env
256+ fromMaybe (internalError "Data constructor not found") $ ctor `M.lookup` dataConstructors env
256257
257258-- |
258259-- Checks whether a data constructor is for a newtype.
src/Language/PureScript/Errors.hs+37−39
@@ -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) =
src/Language/PureScript/Externs.hs+4−3
@@ -38,6 +38,7 @@ import Data.Aeson.TH
3838
3939import qualified Data.Map as M
4040
41+import Language.PureScript.Crash
4142import Language.PureScript.AST
4243import Language.PureScript.Environment
4344import Language.PureScript.Names
@@ -152,7 +153,7 @@ applyExternsFileToEnvironment ExternsFile{..} = flip (foldl' applyDecl) efDeclar
152153
153154-- | Generate an externs file for all declarations in a module
154155moduleToExternsFile :: Module -> Environment -> ExternsFile
155−moduleToExternsFile (Module _ _ _ _ Nothing) _ = error "moduleToExternsFile: module exports were not elaborated"
156+moduleToExternsFile (Module _ _ _ _ Nothing) _ = internalError "moduleToExternsFile: module exports were not elaborated"
156157moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
157158 where
158159 efVersion = showVersion Paths.version
@@ -181,7 +182,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
181182 toExternsDeclaration (PositionedDeclarationRef _ _ r) = toExternsDeclaration r
182183 toExternsDeclaration (TypeRef pn dctors) =
183184 case Qualified (Just mn) pn `M.lookup` types env of
184− Nothing -> error "toExternsDeclaration: no kind in toExternsDeclaration"
185+ Nothing -> internalError "toExternsDeclaration: no kind in toExternsDeclaration"
185186 Just (kind, TypeSynonym)
186187 | Just (args, synTy) <- Qualified (Just mn) pn `M.lookup` typeSynonyms env -> [ EDType pn kind TypeSynonym, EDTypeSynonym pn args synTy ]
187188 Just (kind, ExternData) -> [ EDType pn kind ExternData ]
@@ -190,7 +191,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
190191 | dctor <- fromMaybe (map fst tys) dctors
191192 , (dty, _, ty, args) <- maybeToList (M.lookup (Qualified (Just mn) dctor) (dataConstructors env))
192193 ]
193− _ -> error "toExternsDeclaration: Invalid input"
194+ _ -> internalError "toExternsDeclaration: Invalid input"
194195 toExternsDeclaration (ValueRef ident)
195196 | Just (ty, _, _) <- (mn, ident) `M.lookup` names env
196197 = [ EDValue ident ty ]
src/Language/PureScript/Linter.hs+2−1
@@ -30,6 +30,7 @@ import Control.Applicative
3030#endif
3131import Control.Monad.Writer.Class
3232
33+import Language.PureScript.Crash
3334import Language.PureScript.AST
3435import Language.PureScript.Names
3536import Language.PureScript.Errors
@@ -50,7 +51,7 @@ lint (Module _ _ mn ds _) = censor (addHint (ErrorInModule mn)) $ mapM_ lintDecl
5051 getDeclIdent (ValueDeclaration ident _ _ _) = Just ident
5152 getDeclIdent (ExternDeclaration ident _) = Just ident
5253 getDeclIdent (TypeInstanceDeclaration ident _ _ _ _) = Just ident
53− getDeclIdent (BindingGroupDeclaration _) = error "lint: binding groups should not be desugared yet."
54+ getDeclIdent (BindingGroupDeclaration _) = internalError "lint: binding groups should not be desugared yet."
5455 getDeclIdent _ = Nothing
5556
5657 lintDeclaration :: Declaration -> m ()
src/Language/PureScript/Linter/Exhaustive.hs+3−2
@@ -38,6 +38,7 @@ import Control.Applicative
3838import Control.Arrow (first, second)
3939import Control.Monad.Writer.Class
4040
41+import Language.PureScript.Crash
4142import Language.PureScript.AST.Binders
4243import Language.PureScript.AST.Declarations
4344import Language.PureScript.Environment
@@ -92,7 +93,7 @@ getConstructors env defmn n = extractConstructors lnte
9293
9394 extractConstructors :: Maybe (Kind, TypeKind) -> [(ProperName, [Type])]
9495 extractConstructors (Just (_, DataType _ pt)) = pt
95− extractConstructors _ = error "Data name not in the scope of the current environment in extractConstructors"
96+ extractConstructors _ = internalError "Data name not in the scope of the current environment in extractConstructors"
9697
9798-- |
9899-- Replicates a wildcard binder
@@ -197,7 +198,7 @@ missingCasesMultiple env mn = go
197198 where
198199 (miss1, pr1) = missingCasesSingle env mn x y
199200 (miss2, pr2) = go xs ys
200− go _ _ = error "Argument lengths did not match in missingCasesMultiple."
201+ go _ _ = internalError "Argument lengths did not match in missingCasesMultiple."
201202
202203-- |
203204-- Guard handling
src/Language/PureScript/Make.hs+8−7
@@ -72,6 +72,7 @@ import System.Directory
7272import System.FilePath ((</>), takeDirectory)
7373import System.IO.Error (tryIOError)
7474
75+import Language.PureScript.Crash
7576import Language.PureScript.AST
7677import Language.PureScript.Externs
7778import Language.PureScript.Environment
@@ -166,7 +167,7 @@ make MakeActions{..} ms = do
166167 barriers <- zip (map getModuleName sorted) <$> replicateM (length ms) ((,) <$> C.newEmptyMVar <*> C.newEmptyMVar)
167168
168169 for_ sorted $ \m -> fork $ do
169− let deps = fromMaybe (error "make: module not found in dependency graph.") (lookup (getModuleName m) graph)
170+ let deps = fromMaybe (internalError "make: module not found in dependency graph.") (lookup (getModuleName m) graph)
170171 buildModule barriers (importPrim m) (deps `inOrderOf` map getModuleName sorted)
171172
172173 -- Wait for all threads to complete, and collect errors.
@@ -176,7 +177,7 @@ make MakeActions{..} ms = do
176177 unless (null errors) $ throwError (mconcat errors)
177178
178179 -- Bundle up all the externs and return them as an Environment
179− (warnings, externs) <- unzip . fromMaybe (error "make: externs were missing but no errors reported.") . sequence <$> for barriers (takeMVar . fst . snd)
180+ (warnings, externs) <- unzip . fromMaybe (internalError "make: externs were missing but no errors reported.") . sequence <$> for barriers (takeMVar . fst . snd)
180181 tell (mconcat warnings)
181182 return $ foldl' (flip applyExternsFileToEnvironment) initEnvironment externs
182183
@@ -205,7 +206,7 @@ make MakeActions{..} ms = do
205206 -- We need to wait for dependencies to be built, before checking if the current
206207 -- module should be rebuilt, so the first thing to do is to wait on the
207208 -- MVars for the module's dependencies.
208− mexterns <- fmap unzip . sequence <$> mapM (readMVar . fst . fromMaybe (error "make: no barrier") . flip lookup barriers) deps
209+ mexterns <- fmap unzip . sequence <$> mapM (readMVar . fst . fromMaybe (internalError "make: no barrier") . flip lookup barriers) deps
209210
210211 outputTimestamp <- getOutputTimestamp moduleName
211212 dependencyTimestamp <- maximumMaybe <$> mapM (fmap shouldExist . getOutputTimestamp) deps
@@ -247,8 +248,8 @@ make MakeActions{..} ms = do
247248 where
248249 markComplete :: Maybe (MultipleErrors, ExternsFile) -> Maybe MultipleErrors -> m ()
249250 markComplete externs errors = do
250− putMVar (fst $ fromMaybe (error "make: no barrier") $ lookup moduleName barriers) externs
251− putMVar (snd $ fromMaybe (error "make: no barrier") $ lookup moduleName barriers) errors
251+ putMVar (fst $ fromMaybe (internalError "make: no barrier") $ lookup moduleName barriers) externs
252+ putMVar (snd $ fromMaybe (internalError "make: no barrier") $ lookup moduleName barriers) errors
252253
253254 maximumMaybe :: (Ord a) => [a] -> Maybe a
254255 maximumMaybe [] = Nothing
@@ -257,7 +258,7 @@ make MakeActions{..} ms = do
257258 -- Make sure a dependency exists
258259 shouldExist :: Maybe UTCTime -> UTCTime
259260 shouldExist (Just t) = t
260− shouldExist _ = error "make: dependency should already have been built."
261+ shouldExist _ = internalError "make: dependency should already have been built."
261262
262263 decodeExterns :: B.ByteString -> Maybe ExternsFile
263264 decodeExterns bs = do
@@ -324,7 +325,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
324325
325326 getInputTimestamp :: ModuleName -> Make (Either RebuildPolicy (Maybe UTCTime))
326327 getInputTimestamp mn = do
327− let path = fromMaybe (error "Module has no filename in 'make'") $ M.lookup mn filePathMap
328+ let path = fromMaybe (internalError "Module has no filename in 'make'") $ M.lookup mn filePathMap
328329 e1 <- traverseEither getTimestamp path
329330 fPath <- maybe (return Nothing) getTimestamp $ M.lookup mn foreigns
330331 return $ fmap (max fPath) e1
src/Language/PureScript/ModuleDependencies.hs+2−1
@@ -25,6 +25,7 @@ import Data.Graph
2525import Data.List (nub)
2626import Data.Maybe (fromMaybe, mapMaybe)
2727
28+import Language.PureScript.Crash
2829import Language.PureScript.AST
2930import Language.PureScript.Names
3031import Language.PureScript.Types
@@ -43,7 +44,7 @@ sortModules ms = do
4344 ms' <- mapM toModule $ stronglyConnComp verts
4445 let (graph, fromVertex, toVertex) = graphFromEdges verts
4546 moduleGraph = do (_, mn, _) <- verts
46− let v = fromMaybe (error "sortModules: vertex not found") (toVertex mn)
47+ let v = fromMaybe (internalError "sortModules: vertex not found") (toVertex mn)
4748 deps = reachable graph v
4849 toKey i = case fromVertex i of (_, key, _) -> key
4950 return (mn, filter (/= mn) (map toKey deps))
src/Language/PureScript/Pretty/JS.hs+3−2
@@ -30,6 +30,7 @@ import Control.Monad.State
3030import Control.PatternArrows
3131import qualified Control.Arrow as A
3232
33+import Language.PureScript.Crash
3334import Language.PureScript.CodeGen.JS.AST
3435import Language.PureScript.CodeGen.JS.Common
3536import Language.PureScript.Pretty.Common
@@ -251,13 +252,13 @@ prettyStatements sts = do
251252-- Generate a pretty-printed string representing a Javascript expression
252253--
253254prettyPrintJS1 :: JS -> String
254−prettyPrintJS1 = fromMaybe (error "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyPrintJS'
255+prettyPrintJS1 = fromMaybe (internalError "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyPrintJS'
255256
256257-- |
257258-- Generate a pretty-printed string representing a collection of Javascript expressions at the same indentation level
258259--
259260prettyPrintJS :: [JS] -> String
260−prettyPrintJS = fromMaybe (error "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyStatements
261+prettyPrintJS = fromMaybe (internalError "Incomplete pattern") . flip evalStateT (PrinterState 0) . prettyStatements
261262
262263-- |
263264-- Generate an indented, pretty-printed string representing a Javascript expression
src/Language/PureScript/Pretty/Kinds.hs+2−1
@@ -22,6 +22,7 @@ import Data.Maybe (fromMaybe)
2222import Control.Arrow (ArrowPlus(..))
2323import Control.PatternArrows
2424
25+import Language.PureScript.Crash
2526import Language.PureScript.Kinds
2627import Language.PureScript.Pretty.Common
2728
@@ -47,7 +48,7 @@ funKind = mkPattern match
4748
4849-- | Generate a pretty-printed string representing a Kind
4950prettyPrintKind :: Kind -> String
50−prettyPrintKind = fromMaybe (error "Incomplete pattern") . pattern matchKind ()
51+prettyPrintKind = fromMaybe (internalError "Incomplete pattern") . pattern matchKind ()
5152 where
5253 matchKind :: Pattern () Kind String
5354 matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap parens matchKind)
src/Language/PureScript/Pretty/Types.hs+3−2
@@ -27,6 +27,7 @@ import Data.Maybe (fromMaybe)
2727import Control.Arrow ((<+>))
2828import Control.PatternArrows
2929
30+import Language.PureScript.Crash
3031import Language.PureScript.Types
3132import Language.PureScript.Names
3233import Language.PureScript.Kinds
@@ -136,14 +137,14 @@ forall_ = mkPattern match
136137 match _ = Nothing
137138
138139typeAtomAsBox :: Type -> Box
139−typeAtomAsBox = fromMaybe (error "Incomplete pattern") . pattern matchTypeAtom () . insertPlaceholders
140+typeAtomAsBox = fromMaybe (internalError "Incomplete pattern") . pattern matchTypeAtom () . insertPlaceholders
140141
141142-- | Generate a pretty-printed string representing a Type, as it should appear inside parentheses
142143prettyPrintTypeAtom :: Type -> String
143144prettyPrintTypeAtom = render . typeAtomAsBox
144145
145146typeAsBox :: Type -> Box
146−typeAsBox = fromMaybe (error "Incomplete pattern") . pattern matchType () . insertPlaceholders
147+typeAsBox = fromMaybe (internalError "Incomplete pattern") . pattern matchType () . insertPlaceholders
147148
148149-- | Generate a pretty-printed string representing a Type
149150prettyPrintType :: Type -> String
src/Language/PureScript/Pretty/Values.hs+2−1
@@ -25,6 +25,7 @@ import Data.List (intercalate)
2525
2626import Control.Arrow (second)
2727
28+import Language.PureScript.Crash
2829import Language.PureScript.AST
2930import Language.PureScript.Names
3031import Language.PureScript.Pretty.Common
@@ -103,7 +104,7 @@ prettyPrintDeclaration (BindingGroupDeclaration ds) =
103104 where
104105 toDecl (nm, t, e) = ValueDeclaration nm t [] (Right e)
105106prettyPrintDeclaration (PositionedDeclaration _ _ d) = prettyPrintDeclaration d
106−prettyPrintDeclaration _ = error "Invalid argument to prettyPrintDeclaration"
107+prettyPrintDeclaration _ = internalError "Invalid argument to prettyPrintDeclaration"
107108
108109prettyPrintCaseAlternative :: CaseAlternative -> Box
109110prettyPrintCaseAlternative (CaseAlternative binders result) =
src/Language/PureScript/Sugar/BindingGroups.hs+6−5
@@ -35,6 +35,7 @@ import Control.Monad.Error.Class (MonadError(..))
3535
3636import qualified Data.Set as S
3737
38+import Language.PureScript.Crash
3839import Language.PureScript.AST
3940import Language.PureScript.Names
4041import Language.PureScript.Types
@@ -145,13 +146,13 @@ usedProperNames moduleName =
145146getIdent :: Declaration -> Ident
146147getIdent (ValueDeclaration ident _ _ _) = ident
147148getIdent (PositionedDeclaration _ _ d) = getIdent d
148−getIdent _ = error "Expected ValueDeclaration"
149+getIdent _ = internalError "Expected ValueDeclaration"
149150
150151getProperName :: Declaration -> ProperName
151152getProperName (DataDeclaration _ pn _ _) = pn
152153getProperName (TypeSynonymDeclaration pn _ _) = pn
153154getProperName (PositionedDeclaration _ _ d) = getProperName d
154−getProperName _ = error "Expected DataDeclaration"
155+getProperName _ = internalError "Expected DataDeclaration"
155156
156157-- |
157158-- Convert a group of mutually-recursive dependencies into a BindingGroupDeclaration (or simple ValueDeclaration).
@@ -185,7 +186,7 @@ toBindingGroup moduleName (CyclicSCC ds') =
185186 cycleError (PositionedDeclaration p _ d) ds = rethrowWithPosition p $ cycleError d ds
186187 cycleError (ValueDeclaration n _ _ (Right _)) [] = throwError . errorMessage $ CycleInDeclaration n
187188 cycleError d ds@(_:_) = rethrow (addHint (NotYetDefined (map getIdent ds))) $ cycleError d []
188− cycleError _ _ = error "Expected ValueDeclaration"
189+ cycleError _ _ = internalError "Expected ValueDeclaration"
189190
190191toDataBindingGroup :: (MonadError MultipleErrors m) => SCC Declaration -> m Declaration
191192toDataBindingGroup (AcyclicSCC d) = return d
@@ -203,6 +204,6 @@ isTypeSynonym _ = Nothing
203204
204205fromValueDecl :: Declaration -> (Ident, NameKind, Expr)
205206fromValueDecl (ValueDeclaration ident nameKind [] (Right val)) = (ident, nameKind, val)
206−fromValueDecl ValueDeclaration{} = error "Binders should have been desugared"
207+fromValueDecl ValueDeclaration{} = internalError "Binders should have been desugared"
207208fromValueDecl (PositionedDeclaration _ _ d) = fromValueDecl d
208−fromValueDecl _ = error "Expected ValueDeclaration"
209+fromValueDecl _ = internalError "Expected ValueDeclaration"
src/Language/PureScript/Sugar/CaseDeclarations.hs+3−2
@@ -23,6 +23,7 @@ module Language.PureScript.Sugar.CaseDeclarations (
2323 desugarCasesModule
2424) where
2525
26+import Language.PureScript.Crash
2627import Data.Maybe (catMaybes)
2728import Data.List (nub, groupBy)
2829
@@ -112,7 +113,7 @@ toDecls [ValueDeclaration ident nameKind bs (Right val)] | all isVarBinder bs =
112113 fromVarBinder (VarBinder name) = return name
113114 fromVarBinder (PositionedBinder _ _ b) = fromVarBinder b
114115 fromVarBinder (TypedBinder _ b) = fromVarBinder b
115− fromVarBinder _ = error "fromVarBinder: Invalid argument"
116+ fromVarBinder _ = internalError "fromVarBinder: Invalid argument"
116117toDecls ds@(ValueDeclaration ident _ bs result : _) = do
117118 let tuples = map toTuple ds
118119 unless (all ((== length bs) . length . fst) tuples) $
@@ -129,7 +130,7 @@ toDecls ds = return ds
129130toTuple :: Declaration -> ([Binder], Either [(Guard, Expr)] Expr)
130131toTuple (ValueDeclaration _ _ bs result) = (bs, result)
131132toTuple (PositionedDeclaration _ _ d) = toTuple d
132−toTuple _ = error "Not a value declaration"
133+toTuple _ = internalError "Not a value declaration"
133134
134135makeCaseDeclaration :: forall m. (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => Ident -> [([Binder], Either [(Guard, Expr)] Expr)] -> m Declaration
135136makeCaseDeclaration ident alternatives = do
src/Language/PureScript/Sugar/DoNotation.hs+2−1
@@ -22,6 +22,7 @@ module Language.PureScript.Sugar.DoNotation (
2222 desugarDoModule
2323) where
2424
25+import Language.PureScript.Crash
2526import Language.PureScript.Names
2627import Language.PureScript.AST
2728import Language.PureScript.Errors
@@ -56,7 +57,7 @@ desugarDo d =
5657 replace other = return other
5758
5859 go :: [DoNotationElement] -> m Expr
59− go [] = error "The impossible happened in desugarDo"
60+ go [] = internalError "The impossible happened in desugarDo"
6061 go [DoNotationValue val] = return val
6162 go (DoNotationValue val : rest) = do
6263 rest' <- go rest
src/Language/PureScript/Sugar/Names.hs+2−1
@@ -30,6 +30,7 @@ import Control.Monad.Writer (MonadWriter(..))
3030
3131import qualified Data.Map as M
3232
33+import Language.PureScript.Crash
3334import Language.PureScript.AST
3435import Language.PureScript.Names
3536import Language.PureScript.Types
@@ -99,7 +100,7 @@ desugarImports externs modules = do
99100 renameInModule' :: Env -> Module -> m Module
100101 renameInModule' env m@(Module _ _ mn _ _) =
101102 rethrow (addHint (ErrorInModule mn)) $ do
102− let (_, imps, exps) = fromMaybe (error "Module is missing in renameInModule'") $ M.lookup mn env
103+ let (_, imps, exps) = fromMaybe (internalError "Module is missing in renameInModule'") $ M.lookup mn env
103104 elaborateImports imps <$> renameInModule env imps (elaborateExports exps m)
104105
105106-- |
src/Language/PureScript/Sugar/Names/Exports.hs+8−7
@@ -33,6 +33,7 @@ import Control.Monad.Error.Class (MonadError(..))
3333
3434import qualified Data.Map as M
3535
36+import Language.PureScript.Crash
3637import Language.PureScript.AST
3738import Language.PureScript.Names
3839import Language.PureScript.Errors
@@ -52,7 +53,7 @@ findExportable (Module _ _ mn ds _) =
5253 where
5354 go exps'' (TypeDeclaration name _) = exportValue exps'' name mn
5455 go exps'' (PositionedDeclaration pos _ d) = rethrowWithPosition pos $ go exps'' d
55− go _ _ = error "Invalid declaration in TypeClassDeclaration"
56+ go _ _ = internalError "Invalid declaration in TypeClassDeclaration"
5657 updateExports exps (DataDeclaration _ tn _ dcs) = exportType exps tn (map fst dcs) mn
5758 updateExports exps (TypeSynonymDeclaration tn _ _) = exportType exps tn [] mn
5859 updateExports exps (ExternDataDeclaration tn _) = exportType exps tn [] mn
@@ -137,24 +138,24 @@ resolveExports env mn imps exps refs =
137138 resolveTypeExports tctors dctors = map go tctors
138139 where
139140 go :: Qualified ProperName -> ((ProperName, [ProperName]), ModuleName)
140− go (Qualified (Just mn'') name) = fromMaybe (error "Missing value in resolveTypeExports") $ do
141+ go (Qualified (Just mn'') name) = fromMaybe (internalError "Missing value in resolveTypeExports") $ do
141142 exps' <- envModuleExports <$> mn'' `M.lookup` env
142143 ((_, dctors'), mnOrig) <- find (\((name', _), _) -> name == name') (exportedTypes exps')
143144 let relevantDctors = mapMaybe (\(Qualified mn''' dctor) -> if mn''' == Just mnOrig then Just dctor else Nothing) dctors
144145 return ((name, intersect relevantDctors dctors'), mnOrig)
145− go (Qualified Nothing _) = error "Unqualified value in resolveTypeExports"
146+ go (Qualified Nothing _) = internalError "Unqualified value in resolveTypeExports"
146147
147148
148149 -- Looks up an imported class and re-qualifies it with the original module it
149150 -- came from.
150151 resolveClass :: Qualified ProperName -> (ProperName, ModuleName)
151− resolveClass className = splitQual $ fromMaybe (error "Missing value in resolveClass") $
152+ resolveClass className = splitQual $ fromMaybe (internalError "Missing value in resolveClass") $
152153 resolve exportedTypeClasses className
153154
154155 -- Looks up an imported value and re-qualifies it with the original module it
155156 -- came from.
156157 resolveValue :: Qualified Ident -> (Ident, ModuleName)
157− resolveValue ident = splitQual $ fromMaybe (error "Missing value in resolveValue") $
158+ resolveValue ident = splitQual $ fromMaybe (internalError "Missing value in resolveValue") $
158159 resolve exportedValues ident
159160
160161 resolve :: (Eq a) => (Exports -> [(a, ModuleName)]) -> Qualified a -> Maybe (Qualified a)
@@ -162,13 +163,13 @@ resolveExports env mn imps exps refs =
162163 exps' <- envModuleExports <$> mn'' `M.lookup` env
163164 mn''' <- snd <$> find ((== a) . fst) (f exps')
164165 return $ Qualified (Just mn''') a
165− resolve _ _ = error "Unqualified value in resolve"
166+ resolve _ _ = internalError "Unqualified value in resolve"
166167
167168 -- A partial function that takes a qualified value and extracts the value and
168169 -- qualified module components.
169170 splitQual :: Qualified a -> (a, ModuleName)
170171 splitQual (Qualified (Just mn'') a) = (a, mn'')
171− splitQual _ = error "Unqualified value in splitQual"
172+ splitQual _ = internalError "Unqualified value in splitQual"
172173
173174-- |
174175-- Filters the full list of exportable values, types, and classes for a module
src/Language/PureScript/Sugar/Names/Imports.hs+7−6
@@ -34,6 +34,7 @@ import Control.Monad.Writer (MonadWriter(..), censor)
3434
3535import qualified Data.Map as M
3636
37+import Language.PureScript.Crash
3738import Language.PureScript.AST
3839import Language.PureScript.Names
3940import Language.PureScript.Errors
@@ -115,7 +116,7 @@ resolveImport currentModule importModule exps imps impQual =
115116 checkImportExists UnknownImportTypeClass (fst `map` exportedTypeClasses exps) name
116117 --check (ModuleRef name) =
117118 -- checkImportExists (const UnknownModule) (exportedModules exps) name
118− check _ = error "Invalid argument to checkRefs"
119+ check _ = internalError "Invalid argument to checkRefs"
119120
120121 -- Check that an explicitly imported item exists in the module it is being imported from
121122 checkImportExists :: (Eq a) => (ModuleName -> a -> SimpleErrorMessage) -> [a] -> a -> m ()
@@ -171,13 +172,13 @@ resolveImport currentModule importModule exps imps impQual =
171172 importExplicit imp (TypeClassRef name) = do
172173 typeClasses' <- updateImports (importedTypeClasses imp) runProperName (exportedTypeClasses exps) name
173174 return $ imp { importedTypeClasses = typeClasses' }
174− importExplicit _ _ = error "Invalid argument to importExplicit"
175+ importExplicit _ _ = internalError "Invalid argument to importExplicit"
175176
176177 -- Find all exported data constructors for a given type
177178 allExportedDataConstructors :: ProperName -> [(ProperName, ModuleName)]
178179 allExportedDataConstructors name =
179180 case find ((== name) . fst . fst) (exportedTypes exps) of
180− Nothing -> error "Invalid state in allExportedDataConstructors"
181+ Nothing -> internalError "Invalid state in allExportedDataConstructors"
181182 Just ((_, dctors), mn) -> map (, mn) dctors
182183
183184 -- Add something to the Imports if it does not already exist there
@@ -191,7 +192,7 @@ resolveImport currentModule importModule exps imps impQual =
191192 -- If the name is not already present add it to the list, after looking up
192193 -- where it was originally defined
193194 Nothing ->
194− let mnOrig = fromMaybe (error "Invalid state in updateImports") (name `lookup` exps')
195+ let mnOrig = fromMaybe (internalError "Invalid state in updateImports") (name `lookup` exps')
195196 in return $ M.insert (Qualified impQual name) (Qualified (Just importModule) name, mnOrig) imps'
196197
197198 -- If the name already is present check whether it's a duplicate import
@@ -199,7 +200,7 @@ resolveImport currentModule importModule exps imps impQual =
199200 -- re-exports A, importing A and B in C should not result in a "conflicting
200201 -- import for `x`" error
201202 Just (Qualified (Just mn) _, mnOrig)
202− | mnOrig == fromMaybe (error "Invalid state in updateImports") (name `lookup` exps') -> return imps'
203+ | mnOrig == fromMaybe (internalError "Invalid state in updateImports") (name `lookup` exps') -> return imps'
203204 | otherwise -> throwError . errorMessage $ err
204205 where
205206 err = if currentModule `elem` [mn, importModule]
@@ -207,4 +208,4 @@ resolveImport currentModule importModule exps imps impQual =
207208 else ConflictingImports (render name) mn importModule
208209
209210 Just (Qualified Nothing _, _) ->
210− error "Invalid state in updateImports"
211+ internalError "Invalid state in updateImports"
src/Language/PureScript/Sugar/Operators.hs+3−2
@@ -29,6 +29,7 @@ module Language.PureScript.Sugar.Operators (
2929 desugarOperatorSections
3030) where
3131
32+import Language.PureScript.Crash
3233import Language.PureScript.AST
3334import Language.PureScript.Errors
3435import Language.PureScript.Names
@@ -93,7 +94,7 @@ collectFixities (Module _ _ moduleName ds _) = concatMap collect ds
9394 where
9495 collect :: Declaration -> [(Qualified Ident, SourceSpan, Fixity)]
9596 collect (PositionedDeclaration pos _ (FixityDeclaration fixity name)) = [(Qualified (Just moduleName) (Op name), pos, fixity)]
96− collect FixityDeclaration{} = error "Fixity without srcpos info"
97+ collect FixityDeclaration{} = internalError "Fixity without srcpos info"
9798 collect _ = []
9899
99100ensureNoDuplicates :: (MonadError MultipleErrors m) => [(Qualified Ident, SourceSpan)] -> m ()
@@ -129,7 +130,7 @@ matchOperators ops = parseChains
129130 extendChain (BinaryNoParens op l r) = Left l : Right op : extendChain r
130131 extendChain other = [Left other]
131132 bracketChain :: Chain -> m Expr
132− bracketChain = either (\_ -> error "matchOperators: cannot reorder operators") return . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
133+ bracketChain = either (\_ -> internalError "matchOperators: cannot reorder operators") return . P.parse (P.buildExpressionParser opTable parseValue <* P.eof) "operator expression"
133134 opTable = [P.Infix (P.try (parseTicks >>= \op -> return (\t1 t2 -> App (App op t1) t2))) P.AssocLeft]
134135 : map (map (\(name, f, a) -> P.Infix (P.try (matchOp name) >> return f) (toAssoc a))) ops
135136 ++ [[ P.Infix (P.try (parseOp >>= \ident -> return (\t1 t2 -> App (App (Var ident) t1) t2))) P.AssocLeft ]]
src/Language/PureScript/Sugar/TypeClasses.hs+8−7
@@ -24,6 +24,7 @@ module Language.PureScript.Sugar.TypeClasses
2424 , superClassDictionaryNames
2525 ) where
2626
27+import Language.PureScript.Crash
2728import Language.PureScript.AST hiding (isExported)
2829import Language.PureScript.Environment
2930import Language.PureScript.Errors
@@ -75,7 +76,7 @@ desugarModule (Module ss coms name decls (Just exps)) = do
7576 | isTypeClassDeclaration d1 && not (isTypeClassDeclaration d2) = LT
7677 | not (isTypeClassDeclaration d1) && isTypeClassDeclaration d2 = GT
7778 | otherwise = EQ
78−desugarModule _ = error "Exports should have been elaborated in name desugaring"
79+desugarModule _ = internalError "Exports should have been elaborated in name desugaring"
7980
8081{- Desugar type class and type class instance declarations
8182--
@@ -177,7 +178,7 @@ desugarDecl mn exps = go
177178 go d@(TypeClassDeclaration name args implies members) = do
178179 modify (M.insert (mn, name) (args, implies, members))
179180 return (Nothing, d : typeClassDictionaryDeclaration name args implies members : map (typeClassMemberToDictionaryAccessor mn name args) members)
180− go (TypeInstanceDeclaration _ _ _ _ DerivedInstance) = error "Derived instanced should have been desugared"
181+ go (TypeInstanceDeclaration _ _ _ _ DerivedInstance) = internalError "Derived instanced should have been desugared"
181182 go d@(TypeInstanceDeclaration name deps className tys (ExplicitInstance members)) = do
182183 desugared <- desugarCases members
183184 dictDecl <- typeInstanceDictionaryDeclaration name mn deps className tys desugared
@@ -200,7 +201,7 @@ desugarDecl mn exps = go
200201
201202 isExported :: (ProperName -> [DeclarationRef] -> Bool) -> Qualified ProperName -> Bool
202203 isExported test (Qualified (Just mn') pn) = mn /= mn' || test pn exps
203− isExported _ _ = error "Names should have been qualified in name desugaring"
204+ isExported _ _ = internalError "Names should have been qualified in name desugaring"
204205
205206 matchesTypeRef :: ProperName -> DeclarationRef -> Bool
206207 matchesTypeRef pn (TypeRef pn' _) = pn == pn'
@@ -216,7 +217,7 @@ desugarDecl mn exps = go
216217memberToNameAndType :: Declaration -> (Ident, Type)
217218memberToNameAndType (TypeDeclaration ident ty) = (ident, ty)
218219memberToNameAndType (PositionedDeclaration _ _ d) = memberToNameAndType d
219−memberToNameAndType _ = error "Invalid declaration in type class definition"
220+memberToNameAndType _ = internalError "Invalid declaration in type class definition"
220221
221222typeClassDictionaryDeclaration :: ProperName -> [(String, Maybe Kind)] -> [Constraint] -> [Declaration] -> Declaration
222223typeClassDictionaryDeclaration name args implies members =
@@ -236,7 +237,7 @@ typeClassMemberToDictionaryAccessor mn name args (TypeDeclaration ident ty) =
236237 moveQuantifiersToFront (quantify (ConstrainedType [(className, map (TypeVar . fst) args)] ty))
237238typeClassMemberToDictionaryAccessor mn name args (PositionedDeclaration pos com d) =
238239 PositionedDeclaration pos com $ typeClassMemberToDictionaryAccessor mn name args d
239−typeClassMemberToDictionaryAccessor _ _ _ _ = error "Invalid declaration in type class definition"
240+typeClassMemberToDictionaryAccessor _ _ _ _ = internalError "Invalid declaration in type class definition"
240241
241242unit :: Type
242243unit = TypeApp tyObject REmpty
@@ -294,13 +295,13 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls =
294295 memberToValue tys' (PositionedDeclaration pos com d) = rethrowWithPosition pos $ do
295296 val <- memberToValue tys' d
296297 return (PositionedValue pos com val)
297− memberToValue _ _ = error "Invalid declaration in type instance definition"
298+ memberToValue _ _ = internalError "Invalid declaration in type instance definition"
298299
299300typeClassMemberName :: Declaration -> String
300301typeClassMemberName (TypeDeclaration ident _) = runIdent ident
301302typeClassMemberName (ValueDeclaration ident _ _ _) = runIdent ident
302303typeClassMemberName (PositionedDeclaration _ _ d) = typeClassMemberName d
303−typeClassMemberName _ = error "typeClassMemberName: Invalid declaration in type class definition"
304+typeClassMemberName _ = internalError "typeClassMemberName: Invalid declaration in type class definition"
304305
305306superClassDictionaryNames :: [Constraint] -> [String]
306307superClassDictionaryNames supers =
src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+4−3
@@ -36,6 +36,7 @@ import Control.Monad (replicateM)
3636import Control.Monad.Supply.Class (MonadSupply, freshName)
3737import Control.Monad.Error.Class (MonadError(..))
3838
39+import Language.PureScript.Crash
3940import Language.PureScript.AST
4041import Language.PureScript.Environment
4142import Language.PureScript.Errors
@@ -116,7 +117,7 @@ mkSpineFunction mn (DataDeclaration _ _ _ args) = lamCase "$x" <$> mapM mkCtorCl
116117 $ decomposeRec rec
117118 toSpineFun i _ = lamNull $ App (mkGenVar C.toSpine) i
118119mkSpineFunction mn (PositionedDeclaration _ _ d) = mkSpineFunction mn d
119−mkSpineFunction _ _ = error "mkSpineFunction: expected DataDeclaration"
120+mkSpineFunction _ _ = internalError "mkSpineFunction: expected DataDeclaration"
120121
121122mkSignatureFunction :: ModuleName -> Declaration -> Expr
122123mkSignatureFunction _ (DataDeclaration _ _ _ args) = lamNull . mkSigProd $ map mkProdClause args
@@ -145,7 +146,7 @@ mkSignatureFunction _ (DataDeclaration _ _ _ args) = lamNull . mkSigProd $ map m
145146 mkProductSignature typ = lamNull $ App (mkGenVar C.toSignature)
146147 (TypedValue False (mkGenVar "anyProxy") (proxy typ))
147148mkSignatureFunction mn (PositionedDeclaration _ _ d) = mkSignatureFunction mn d
148−mkSignatureFunction _ _ = error "mkSignatureFunction: expected DataDeclaration"
149+mkSignatureFunction _ _ = internalError "mkSignatureFunction: expected DataDeclaration"
149150
150151mkFromSpineFunction :: forall m. (Functor m, MonadSupply m) => ModuleName -> Declaration -> m Expr
151152mkFromSpineFunction mn (DataDeclaration _ _ _ args) = lamCase "$x" <$> (addCatch <$> mapM mkAlternative args)
@@ -194,7 +195,7 @@ mkFromSpineFunction mn (DataDeclaration _ _ _ args) = lamCase "$x" <$> (addCatch
194195 mkRecFun xs = mkJust $ foldr (\s e -> lam s e) recLiteral (map fst xs)
195196 where recLiteral = ObjectLiteral $ map (\(s,_) -> (s,mkVar s)) xs
196197mkFromSpineFunction mn (PositionedDeclaration _ _ d) = mkFromSpineFunction mn d
197−mkFromSpineFunction _ _ = error "mkFromSpineFunction: expected DataDeclaration"
198+mkFromSpineFunction _ _ = internalError "mkFromSpineFunction: expected DataDeclaration"
198199
199200-- Helpers
200201
src/Language/PureScript/Sugar/TypeDeclarations.hs+2−1
@@ -29,6 +29,7 @@ import Control.Monad (forM, when)
2929import Control.Monad.Error.Class (MonadError(..))
3030import Control.Monad.Writer.Class (MonadWriter(tell))
3131
32+import Language.PureScript.Crash
3233import Language.PureScript.AST
3334import Language.PureScript.Names
3435import Language.PureScript.Environment
@@ -63,7 +64,7 @@ desugarTypeDeclarationsModule ms = forM ms $ \(Module ss coms name ds exps) ->
6364 -- At the top level, match a type signature or emit a warning.
6465 when reqd $ case val of
6566 Right TypedValue{} -> return ()
66− Left _ -> error "desugarTypeDeclarations: cases were not desugared"
67+ Left _ -> internalError "desugarTypeDeclarations: cases were not desugared"
6768 _ -> tell (addHint (ErrorInValueDeclaration name) $ errorMessage $ MissingTypeDeclaration name)
6869 let (_, f, _) = everywhereOnValuesTopDownM return go return
6970 f' (Left gs) = Left <$> mapM (pairM return f) gs
src/Language/PureScript/TypeChecker.hs+14−13
@@ -38,6 +38,7 @@ import Control.Applicative ((<$>), (<*))
3838import Control.Monad.State
3939import Control.Monad.Error.Class (MonadError(..))
4040
41+import Language.PureScript.Crash
4142import Language.PureScript.Types
4243import Language.PureScript.Names
4344import Language.PureScript.Kinds
@@ -90,7 +91,7 @@ addTypeClass moduleName pn args implies ds =
9091 where
9192 toPair (TypeDeclaration ident ty) = (ident, ty)
9293 toPair (PositionedDeclaration _ _ d) = toPair d
93− toPair _ = error "Invalid declaration in TypeClassDeclaration"
94+ toPair _ = internalError "Invalid declaration in TypeClassDeclaration"
9495
9596addTypeClassDictionaries :: Maybe ModuleName -> M.Map (Qualified ProperName) (M.Map (Qualified Ident) TypeClassDictionaryInScope) -> Check ()
9697addTypeClassDictionaries mn entries =
@@ -147,8 +148,8 @@ typeCheckAll moduleName _ ds = mapM go ds <* mapM_ checkOrphanFixities ds
147148 where
148149 checkNewtype :: [(ProperName, [Type])] -> Check ()
149150 checkNewtype [(_, [_])] = return ()
150− checkNewtype [(_, _)] = throwError . errorMessage $ InvalidNewtype
151− checkNewtype _ = throwError . errorMessage $ InvalidNewtype
151+ checkNewtype [(_, _)] = throwError . errorMessage $ InvalidNewtype name
152+ checkNewtype _ = throwError . errorMessage $ InvalidNewtype name
152153 go (d@(DataBindingGroupDeclaration tys)) = do
153154 warnAndRethrow (addHint ErrorInDataBindingGroup) $ do
154155 let syns = mapMaybe toTypeSynonym tys
@@ -177,14 +178,14 @@ typeCheckAll moduleName _ ds = mapM go ds <* mapM_ checkOrphanFixities ds
177178 let args' = args `withKinds` kind
178179 addTypeSynonym moduleName name args' ty kind
179180 return $ TypeSynonymDeclaration name args ty
180− go (TypeDeclaration{}) = error "Type declarations should have been removed"
181+ go (TypeDeclaration{}) = internalError "Type declarations should have been removed"
181182 go (ValueDeclaration name nameKind [] (Right val)) =
182183 warnAndRethrow (addHint (ErrorInValueDeclaration name)) $ do
183184 valueIsNotDefined moduleName name
184185 [(_, (val', ty))] <- typesOf moduleName [(name, val)]
185186 addValue moduleName name ty nameKind
186187 return $ ValueDeclaration name nameKind [] $ Right val'
187− go (ValueDeclaration{}) = error "Binders were not desugared"
188+ go (ValueDeclaration{}) = internalError "Binders were not desugared"
188189 go (BindingGroupDeclaration vals) =
189190 warnAndRethrow (addHint (ErrorInBindingGroup (map (\(ident, _, _) -> ident) vals))) $ do
190191 forM_ (map (\(ident, _, _) -> ident) vals) $ \name ->
@@ -245,7 +246,7 @@ typeCheckAll moduleName _ ds = mapM go ds <* mapM_ checkOrphanFixities ds
245246 memberName :: Declaration -> Ident
246247 memberName (ValueDeclaration ident _ _ _) = ident
247248 memberName (PositionedDeclaration _ _ d) = memberName d
248− memberName _ = error "checkInstanceMembers: Invalid declaration in type instance definition"
249+ memberName _ = internalError "checkInstanceMembers: Invalid declaration in type instance definition"
249250
250251 firstDuplicate :: (Eq a) => [a] -> Maybe a
251252 firstDuplicate (x : xs@(y : _))
@@ -261,10 +262,10 @@ typeCheckAll moduleName _ ds = mapM go ds <* mapM_ checkOrphanFixities ds
261262 checkType :: Type -> Bool
262263 checkType (TypeVar _) = False
263264 checkType (TypeConstructor (Qualified (Just mn'') _)) = moduleName == mn''
264− checkType (TypeConstructor (Qualified Nothing _)) = error "Unqualified type name in checkOrphanInstance"
265+ checkType (TypeConstructor (Qualified Nothing _)) = internalError "Unqualified type name in checkOrphanInstance"
265266 checkType (TypeApp t1 _) = checkType t1
266− checkType _ = error "Invalid type in instance in checkOrphanInstance"
267− checkOrphanInstance _ _ _ = error "Unqualified class name in checkOrphanInstance"
267+ checkType _ = internalError "Invalid type in instance in checkOrphanInstance"
268+ checkOrphanInstance _ _ _ = internalError "Unqualified class name in checkOrphanInstance"
268269
269270 -- |
270271 -- This function adds the argument kinds for a type constructor so that they may appear in the externs file,
@@ -274,14 +275,14 @@ typeCheckAll moduleName _ ds = mapM go ds <* mapM_ checkOrphanFixities ds
274275 withKinds [] _ = []
275276 withKinds (s@(_, Just _ ):ss) (FunKind _ k) = s : withKinds ss k
276277 withKinds ( (s, Nothing):ss) (FunKind k1 k2) = (s, Just k1) : withKinds ss k2
277− withKinds _ _ = error "Invalid arguments to peelKinds"
278+ withKinds _ _ = internalError "Invalid arguments to peelKinds"
278279
279280-- |
280281-- Type check an entire module and ensure all types and classes defined within the module that are
281282-- required by exported members are also exported.
282283--
283284typeCheckModule :: Module -> Check Module
284−typeCheckModule (Module _ _ _ _ Nothing) = error "exports should have been elaborated"
285+typeCheckModule (Module _ _ _ _ Nothing) = internalError "exports should have been elaborated"
285286typeCheckModule (Module ss coms mn decls (Just exps)) = warnAndRethrow (addHint (ErrorInModule mn)) $ do
286287 modify (\s -> s { checkCurrentModule = Just mn })
287288 decls' <- typeCheckAll mn exps decls
@@ -331,7 +332,7 @@ typeCheckModule (Module ss coms mn decls (Just exps)) = warnAndRethrow (addHint
331332 findTcons :: Type -> [DeclarationRef]
332333 findTcons = everythingOnTypes (++) go
333334 where
334− go (TypeConstructor (Qualified (Just mn') name)) | mn' == mn = [TypeRef name (error "Data constructors unused in checkTypesAreExported")]
335+ go (TypeConstructor (Qualified (Just mn') name)) | mn' == mn = [TypeRef name (internalError "Data constructors unused in checkTypesAreExported")]
335336 go _ = []
336337
337338 -- Check that all the classes defined in the current module that appear in member types have also
@@ -361,5 +362,5 @@ typeCheckModule (Module ss coms mn decls (Just exps)) = warnAndRethrow (addHint
361362 extractMemberName :: Declaration -> Ident
362363 extractMemberName (PositionedDeclaration _ _ d) = extractMemberName d
363364 extractMemberName (TypeDeclaration memberName _) = memberName
364− extractMemberName _ = error "Unexpected declaration in typeclass member list"
365+ extractMemberName _ = internalError "Unexpected declaration in typeclass member list"
365366 checkClassMembersAreExported _ = return ()
src/Language/PureScript/TypeChecker/Entailment.hs+3−2
@@ -35,6 +35,7 @@ import Control.Monad.State
3535import Control.Monad.Error.Class (MonadError(..))
3636import Control.Monad.Writer.Class (tell)
3737
38+import Language.PureScript.Crash
3839import Language.PureScript.AST
3940import Language.PureScript.Errors
4041import Language.PureScript.Names
@@ -53,11 +54,11 @@ entails moduleName context = solve
5354 where
5455 forClassName :: Qualified ProperName -> [Type] -> [TypeClassDictionaryInScope]
5556 forClassName cn@(Qualified (Just mn) _) tys = concatMap (findDicts cn) (Nothing : Just mn : map Just (mapMaybe ctorModules tys))
56− forClassName _ _ = error "forClassName: expected qualified class name"
57+ forClassName _ _ = internalError "forClassName: expected qualified class name"
5758
5859 ctorModules :: Type -> Maybe ModuleName
5960 ctorModules (TypeConstructor (Qualified (Just mn) _)) = Just mn
60− ctorModules (TypeConstructor (Qualified Nothing _)) = error "ctorModules: unqualified type name"
61+ ctorModules (TypeConstructor (Qualified Nothing _)) = internalError "ctorModules: unqualified type name"
6162 ctorModules (TypeApp ty _) = ctorModules ty
6263 ctorModules _ = Nothing
6364
src/Language/PureScript/TypeChecker/Kinds.hs+2−1
@@ -40,6 +40,7 @@ import Control.Monad.Error.Class (MonadError(..))
4040import Control.Monad.State
4141import Control.Monad.Unify
4242
43+import Language.PureScript.Crash
4344import Language.PureScript.Environment
4445import Language.PureScript.Errors
4546import Language.PureScript.Kinds
@@ -220,4 +221,4 @@ infer' other = (, []) <$> go other
220221 k <- go ty
221222 k =?= Star
222223 return Star
223− go _ = error "Invalid argument to infer"
224+ go _ = internalError "Invalid argument to infer"
src/Language/PureScript/TypeChecker/Monad.hs+1−1
@@ -153,7 +153,7 @@ checkVisibility :: (e ~ MultipleErrors, Functor m, MonadState CheckState m, Mona
153153checkVisibility currentModule name@(Qualified _ var) = do
154154 vis <- getVisibility currentModule name
155155 case vis of
156− Undefined -> throwError . errorMessage $ NameNotInScope var
156+ Undefined -> throwError . errorMessage $ CycleInDeclaration var
157157 _ -> return ()
158158
159159-- |
src/Language/PureScript/TypeChecker/Skolems.hs+2−1
@@ -33,6 +33,7 @@ import Control.Applicative
3333import Control.Monad.Error.Class (MonadError(..))
3434import Control.Monad.Unify
3535
36+import Language.PureScript.Crash
3637import Language.PureScript.AST
3738import Language.PureScript.Errors
3839import Language.PureScript.TypeChecker.Monad
@@ -115,4 +116,4 @@ skolemEscapeCheck root@TypedValue{} =
115116 where
116117 go' val@(TypedValue _ _ (ForAll _ _ (Just sco'))) | sco == sco' = First (Just val)
117118 go' _ = mempty
118−skolemEscapeCheck _ = error "Untyped value passed to skolemEscapeCheck"
119+skolemEscapeCheck _ = internalError "Untyped value passed to skolemEscapeCheck"
src/Language/PureScript/TypeChecker/Subsumption.hs+2−1
@@ -22,6 +22,7 @@ import Data.Ord (comparing)
2222
2323import Control.Monad.Unify
2424
25+import Language.PureScript.Crash
2526import Language.PureScript.AST
2627import Language.PureScript.Environment
2728import Language.PureScript.Errors
@@ -49,7 +50,7 @@ subsumes' val ty1 (ForAll ident ty2 sco) =
4950 sko <- newSkolemConstant
5051 let sk = skolemize ident sko sco' ty2
5152 subsumes val ty1 sk
52− Nothing -> error "subsumes: unspecified skolem scope"
53+ Nothing -> internalError "subsumes: unspecified skolem scope"
5354subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
5455 _ <- subsumes Nothing arg2 arg1
5556 _ <- subsumes Nothing ret1 ret2
src/Language/PureScript/TypeChecker/Types.hs+13−12
@@ -51,6 +51,7 @@ import Control.Monad.State
5151import Control.Monad.Unify
5252import Control.Monad.Error.Class (MonadError(..))
5353
54+import Language.PureScript.Crash
5455import Language.PureScript.AST
5556import Language.PureScript.Environment
5657import Language.PureScript.Errors
@@ -138,7 +139,7 @@ typeForBindingGroupElement :: (Ident, Expr) -> TypeData -> UntypedData -> UnifyT
138139typeForBindingGroupElement (ident, val) dict untypedDict = do
139140 -- Infer the type with the new names in scope
140141 TypedValue _ val' ty <- bindNames dict $ infer val
141− ty =?= fromMaybe (error "name not found in dictionary") (lookup ident untypedDict)
142+ ty =?= fromMaybe (internalError "name not found in dictionary") (lookup ident untypedDict)
142143 return (ident, (TypedValue True val' ty, ty))
143144
144145-- |
@@ -189,7 +190,7 @@ instantiatePolyTypeWithUnknowns val (ForAll ident ty _) = do
189190 instantiatePolyTypeWithUnknowns val ty'
190191instantiatePolyTypeWithUnknowns val (ConstrainedType constraints ty) = do
191192 dicts <- getTypeClassDictionaries
192− (_, ty') <- instantiatePolyTypeWithUnknowns (error "Types under a constraint cannot themselves be constrained") ty
193+ (_, ty') <- instantiatePolyTypeWithUnknowns (internalError "Types under a constraint cannot themselves be constrained") ty
193194 return (foldl App val (map (flip TypeClassDictionary dicts) constraints), ty')
194195instantiatePolyTypeWithUnknowns val ty = return (val, ty)
195196
@@ -239,7 +240,7 @@ infer' (Abs (Left arg) ret) = do
239240 withBindingGroupVisible $ bindLocalVariables moduleName [(arg, ty, Defined)] $ do
240241 body@(TypedValue _ _ bodyTy) <- infer' ret
241242 return $ TypedValue True (Abs (Left arg) body) $ function ty bodyTy
242−infer' (Abs (Right _) _) = error "Binder was not desugared"
243+infer' (Abs (Right _) _) = internalError "Binder was not desugared"
243244infer' (App f arg) = do
244245 f'@(TypedValue _ _ ft) <- infer f
245246 (ret, app) <- checkFunctionApplication f' ft arg Nothing
@@ -284,7 +285,7 @@ infer' (TypedValue checkType val ty) = do
284285 val' <- if checkType then withScopedTypeVars moduleName args (check val ty') else return val
285286 return $ TypedValue True val' ty'
286287infer' (PositionedValue pos _ val) = warnAndRethrowWithPosition pos $ infer' val
287−infer' _ = error "Invalid argument to infer"
288+infer' _ = internalError "Invalid argument to infer"
288289
289290inferLetBinding :: [Declaration] -> [Declaration] -> Expr -> (Expr -> UnifyT Type Check Expr) -> UnifyT Type Check ([Declaration], Expr)
290291inferLetBinding seen [] ret j = (,) seen <$> withBindingGroupVisible (j ret)
@@ -315,7 +316,7 @@ inferLetBinding seen (BindingGroupDeclaration ds : rest) ret j = do
315316inferLetBinding seen (PositionedDeclaration pos com d : ds) ret j = warnAndRethrowWithPosition pos $ do
316317 (d' : ds', val') <- inferLetBinding seen (d : ds) ret j
317318 return (PositionedDeclaration pos com d' : ds', val')
318−inferLetBinding _ _ _ _ = error "Invalid argument to inferLetBinding"
319+inferLetBinding _ _ _ _ = internalError "Invalid argument to inferLetBinding"
319320
320321-- |
321322-- Infer the types of variables brought into scope by a binder
@@ -332,7 +333,7 @@ inferBinder val (ConstructorBinder ctor binders) = do
332333 env <- getEnv
333334 case M.lookup ctor (dataConstructors env) of
334335 Just (_, _, ty, _) -> do
335− (_, fn) <- instantiatePolyTypeWithUnknowns (error "Data constructor types cannot contain constraints") ty
336+ (_, fn) <- instantiatePolyTypeWithUnknowns (internalError "Data constructor types cannot contain constraints") ty
336337 fn' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ fn
337338 go binders fn'
338339 where
@@ -449,7 +450,7 @@ check' val t@(ConstrainedType constraints ty) = do
449450 newDictionaries :: [(Qualified ProperName, Integer)] -> Qualified Ident -> (Qualified ProperName, [Type]) -> Check [TypeClassDictionaryInScope]
450451 newDictionaries path name (className, instanceTy) = do
451452 tcs <- gets (typeClasses . checkEnv)
452− let (args, _, superclasses) = fromMaybe (error "newDictionaries: type class lookup failed") $ M.lookup className tcs
453+ let (args, _, superclasses) = fromMaybe (internalError "newDictionaries: type class lookup failed") $ M.lookup className tcs
453454 supDicts <- join <$> zipWithM (\(supName, supArgs) index ->
454455 newDictionaries ((supName, index) : path)
455456 name
@@ -484,7 +485,7 @@ check' (Abs (Left arg) ret) ty@(TypeApp (TypeApp t argTy) retTy) = do
484485 Just moduleName <- checkCurrentModule <$> get
485486 ret' <- withBindingGroupVisible $ bindLocalVariables moduleName [(arg, argTy, Defined)] $ check ret retTy
486487 return $ TypedValue True (Abs (Left arg) ret') ty
487−check' (Abs (Right _) _) _ = error "Binder was not desugared"
488+check' (Abs (Right _) _) _ = internalError "Binder was not desugared"
488489check' (App f arg) ret = do
489490 f'@(TypedValue _ _ ft) <- infer f
490491 (_, app) <- checkFunctionApplication f' ft arg (Just ret)
@@ -496,7 +497,7 @@ check' v@(Var var) ty = do
496497 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
497498 v' <- subsumes (Just v) repl ty'
498499 case v' of
499− Nothing -> error "check: unable to check the subsumes relation."
500+ Nothing -> internalError "check: unable to check the subsumes relation."
500501 Just v'' -> return $ TypedValue True v'' ty'
501502check' (SuperClassDictionary className tys) _ = do
502503 {-
@@ -515,7 +516,7 @@ check' (TypedValue checkType val ty1) ty2 = do
515516 ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty2
516517 val' <- subsumes (Just val) ty1' ty2'
517518 case val' of
518− Nothing -> error "check: unable to check the subsumes relation."
519+ Nothing -> internalError "check: unable to check the subsumes relation."
519520 Just _ -> do
520521 val''' <- if checkType then withScopedTypeVars moduleName args (check val ty2') else return val
521522 return $ TypedValue checkType val''' ty2'
@@ -557,7 +558,7 @@ check' v@(Constructor c) ty = do
557558 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
558559 mv <- subsumes (Just v) repl ty
559560 case mv of
560− Nothing -> error "check: unable to check the subsumes relation."
561+ Nothing -> internalError "check: unable to check the subsumes relation."
561562 Just v' -> return $ TypedValue True v' ty
562563check' (Let ds val) ty = do
563564 (ds', val') <- inferLetBinding [] ds val (`check` ty)
@@ -572,7 +573,7 @@ check' val ty = do
572573 TypedValue _ val' ty' <- infer val
573574 mt <- subsumes (Just val') ty' ty
574575 case mt of
575− Nothing -> error "check: unable to check the subsumes relation."
576+ Nothing -> internalError "check: unable to check the subsumes relation."
576577 Just v' -> return $ TypedValue True v' ty
577578
578579-- |
src/Language/PureScript/TypeChecker/Unify.hs+3−2
@@ -36,6 +36,7 @@ import Control.Monad.Unify
3636import Control.Monad.Writer
3737import Control.Monad.Error.Class (MonadError(..))
3838
39+import Language.PureScript.Crash
3940import Language.PureScript.Errors
4041import Language.PureScript.TypeChecker.Monad
4142import Language.PureScript.TypeChecker.Skolems
@@ -74,12 +75,12 @@ unifyTypes t1 t2 = rethrow (addHint (ErrorUnifyingTypes t1 t2)) $
7475 let sk1 = skolemize ident1 sko sc1' ty1
7576 let sk2 = skolemize ident2 sko sc2' ty2
7677 sk1 `unifyTypes` sk2
77− _ -> error "unifyTypes: unspecified skolem scope"
78+ _ -> internalError "unifyTypes: unspecified skolem scope"
7879 unifyTypes' (ForAll ident ty1 (Just sc)) ty2 = do
7980 sko <- newSkolemConstant
8081 let sk = skolemize ident sko sc ty1
8182 sk `unifyTypes` ty2
82− unifyTypes' ForAll{} _ = error "unifyTypes: unspecified skolem scope"
83+ unifyTypes' ForAll{} _ = internalError "unifyTypes: unspecified skolem scope"
8384 unifyTypes' ty f@ForAll{} = f `unifyTypes` ty
8485 unifyTypes' (TypeVar v1) (TypeVar v2) | v1 == v2 = return ()
8586 unifyTypes' ty1@(TypeConstructor c1) ty2@(TypeConstructor c2) =
tests/Main.hs+2−2
@@ -78,7 +78,7 @@ modulesDir :: FilePath
7878modulesDir = ".test_modules" </> "node_modules"
7979
8080makeActions :: M.Map P.ModuleName FilePath -> P.MakeActions P.Make
81−makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input file map was read.") foreigns False)
81+makeActions foreigns = (P.buildMakeActions modulesDir (P.internalError "makeActions: input file map was read.") foreigns False)
8282 { P.getInputTimestamp = getInputTimestamp
8383 , P.getOutputTimestamp = getOutputTimestamp
8484 }
@@ -94,7 +94,7 @@ makeActions foreigns = (P.buildMakeActions modulesDir (error "makeActions: input
9494 getOutputTimestamp mn = do
9595 let filePath = modulesDir </> P.runModuleName mn
9696 exists <- liftIO $ doesDirectoryExist filePath
97− return (if exists then Just (error "getOutputTimestamp: read timestamp") else Nothing)
97+ return (if exists then Just (P.internalError "getOutputTimestamp: read timestamp") else Nothing)
9898
9999readInput :: [FilePath] -> IO [(FilePath, String)]
100100readInput inputFiles = forM inputFiles $ \inputFile -> do
tests/common/TestsSetup.hs+3−1
@@ -28,6 +28,8 @@ import System.Process
2828import System.Directory
2929import System.Info
3030
31+import Language.PureScript.Crash
32+
3133findNodeProcess :: IO (Maybe String)
3234findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
3335 where
@@ -35,7 +37,7 @@ findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
3537
3638fetchSupportCode :: IO ()
3739fetchSupportCode = do
38− node <- fromMaybe (error "cannot find node executable") <$> findNodeProcess
40+ node <- fromMaybe (internalError "cannot find node executable") <$> findNodeProcess
3941 setCurrentDirectory "tests/support"
4042 if System.Info.os == "mingw32"
4143 then callProcess "setup-win.cmd" []