git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1556 from purescript/friendly

Friendlier errors

commitfda24b5f9b03b896a0d435dbb302be33f8dee6b9 authorPhil Freeman <paf31@cantab.net> dateSun 25 Oct 2015, 10:30 (11 years ago) parent0e6bfae3aa0748
40 files changed+253−213
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+103−107 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+9−8 src/Language/PureScript/Sugar/TypeClasses/Deriving.hs+4−3 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−2 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+103−107
@@ -41,8 +41,8 @@ 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
45−import Language.PureScript.Environment (isObject, isFunction)
4646import Language.PureScript.Pretty
4747import Language.PureScript.Types
4848import Language.PureScript.Names
@@ -62,13 +62,11 @@ data SimpleErrorMessage
6262 | MissingFFIModule ModuleName
6363 | MultipleFFIModules ModuleName [FilePath]
6464 | UnnecessaryFFIModule ModuleName FilePath
65− | InvalidExternsFile FilePath
6665 | CannotGetFileInfo FilePath
6766 | CannotReadFile FilePath
6867 | CannotWriteFile FilePath
6968 | InfiniteType Type
7069 | InfiniteKind Kind
71− | CannotReorderOperators
7270 | MultipleFixities Ident
7371 | OrphanTypeDeclaration Ident
7472 | OrphanFixityDeclaration String
@@ -108,11 +106,9 @@ data SimpleErrorMessage
108106 | CycleInTypeSynonym (Maybe ProperName)
109107 | CycleInModules [ModuleName]
110108 | NameIsUndefined Ident
111− | NameNotInScope Ident
112109 | UndefinedTypeVariable ProperName
113110 | PartiallyAppliedSynonym (Qualified ProperName)
114111 | EscapedSkolem (Maybe Expr)
115− | UnspecifiedSkolemScope
116112 | TypesDoNotUnify Type Type
117113 | KindsDoNotUnify Kind Kind
118114 | ConstrainedTypeUnified Type Type
@@ -126,16 +122,15 @@ data SimpleErrorMessage
126122 | ArgListLengthsDiffer Ident
127123 | OverlappingArgNames (Maybe Ident)
128124 | MissingClassMember Ident
129− | ExtraneousClassMember Ident
125+ | ExtraneousClassMember Ident (Qualified ProperName)
130126 | ExpectedType Type Kind
131127 | IncorrectConstructorArity (Qualified ProperName)
132− | SubsumptionCheckFailed
133128 | ExprDoesNotHaveType Expr Type
134129 | PropertyIsMissing String Type
135130 | CannotApplyFunction Type Expr
136131 | TypeSynonymInstance
137132 | OrphanInstance Ident (Qualified ProperName) [Type]
138− | InvalidNewtype
133+ | InvalidNewtype ProperName
139134 | InvalidInstanceHead Type
140135 | TransitiveExportError DeclarationRef [DeclarationRef]
141136 | ShadowedName Ident
@@ -202,13 +197,11 @@ errorCode em = case unwrapErrorMessage em of
202197 MissingFFIModule{} -> "MissingFFIModule"
203198 MultipleFFIModules{} -> "MultipleFFIModules"
204199 UnnecessaryFFIModule{} -> "UnnecessaryFFIModule"
205− InvalidExternsFile{} -> "InvalidExternsFile"
206200 CannotGetFileInfo{} -> "CannotGetFileInfo"
207201 CannotReadFile{} -> "CannotReadFile"
208202 CannotWriteFile{} -> "CannotWriteFile"
209203 InfiniteType{} -> "InfiniteType"
210204 InfiniteKind{} -> "InfiniteKind"
211− CannotReorderOperators -> "CannotReorderOperators"
212205 MultipleFixities{} -> "MultipleFixities"
213206 OrphanTypeDeclaration{} -> "OrphanTypeDeclaration"
214207 OrphanFixityDeclaration{} -> "OrphanFixityDeclaration"
@@ -248,11 +241,9 @@ errorCode em = case unwrapErrorMessage em of
248241 CycleInTypeSynonym{} -> "CycleInTypeSynonym"
249242 CycleInModules{} -> "CycleInModules"
250243 NameIsUndefined{} -> "NameIsUndefined"
251− NameNotInScope{} -> "NameNotInScope"
252244 UndefinedTypeVariable{} -> "UndefinedTypeVariable"
253245 PartiallyAppliedSynonym{} -> "PartiallyAppliedSynonym"
254246 EscapedSkolem{} -> "EscapedSkolem"
255− UnspecifiedSkolemScope -> "UnspecifiedSkolemScope"
256247 TypesDoNotUnify{} -> "TypesDoNotUnify"
257248 KindsDoNotUnify{} -> "KindsDoNotUnify"
258249 ConstrainedTypeUnified{} -> "ConstrainedTypeUnified"
@@ -269,13 +260,12 @@ errorCode em = case unwrapErrorMessage em of
269260 ExtraneousClassMember{} -> "ExtraneousClassMember"
270261 ExpectedType{} -> "ExpectedType"
271262 IncorrectConstructorArity{} -> "IncorrectConstructorArity"
272− SubsumptionCheckFailed -> "SubsumptionCheckFailed"
273263 ExprDoesNotHaveType{} -> "ExprDoesNotHaveType"
274264 PropertyIsMissing{} -> "PropertyIsMissing"
275265 CannotApplyFunction{} -> "CannotApplyFunction"
276266 TypeSynonymInstance -> "TypeSynonymInstance"
277267 OrphanInstance{} -> "OrphanInstance"
278− InvalidNewtype -> "InvalidNewtype"
268+ InvalidNewtype{} -> "InvalidNewtype"
279269 InvalidInstanceHead{} -> "InvalidInstanceHead"
280270 TransitiveExportError{} -> "TransitiveExportError"
281271 ShadowedName{} -> "ShadowedName"
@@ -385,9 +375,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
385375 prettyPrintErrorMessage (ErrorMessage hints simple) =
386376 paras $
387377 map renderHint hints ++
388− renderSimpleErrorMessage simple :
389− suggestions simple ++
390− [line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."]
378+ [ renderSimpleErrorMessage simple
379+ , line $ "See " ++ wikiUri ++ " for more information, or to contribute content related to this " ++ levelText ++ "."
380+ ]
391381 where
392382 wikiUri :: String
393383 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
@@ -410,7 +400,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
410400 , prettyPrintParseError err
411401 ]
412402 renderSimpleErrorMessage (ErrorParsingFFIModule path) =
413− paras [ line "Unable to parse module from FFI file: "
403+ paras [ line "Unable to parse foreign module:"
414404 , indent . line $ path
415405 ]
416406 renderSimpleErrorMessage (ErrorParsingModule err) =
@@ -418,29 +408,22 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
418408 , prettyPrintParseError err
419409 ]
420410 renderSimpleErrorMessage (MissingFFIModule mn) =
421− line $ "Missing FFI implementations for module " ++ runModuleName mn
411+ line $ "The foreign module implementation for module " ++ runModuleName mn ++ " is missing."
422412 renderSimpleErrorMessage (UnnecessaryFFIModule mn path) =
423− paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
413+ paras [ line $ "An unnecessary foreign module implementation was provided for module " ++ runModuleName mn ++ ": "
424414 , indent . line $ path
415+ , line $ "Module " ++ runModuleName mn ++ " does not contain any foreign import declarations, so a foreign module is not necessary."
425416 ]
426417 renderSimpleErrorMessage (MultipleFFIModules mn paths) =
427− paras [ line $ "Multiple FFI implementations have been provided for module " ++ runModuleName mn ++ ": "
418+ paras [ line $ "Multiple foreign module implementations have been provided for module " ++ runModuleName mn ++ ": "
428419 , indent . paras $ map line paths
429420 ]
430− renderSimpleErrorMessage (InvalidExternsFile path) =
431− paras [ line "Externs file is invalid: "
432− , indent . line $ path
433− ]
434421 renderSimpleErrorMessage InvalidDoBind =
435− line "Bind statement cannot be the last statement in a do block. The last statement must be an expression."
422+ line "The last statement in a 'do' block must be an expression, but this block ends with a binder."
436423 renderSimpleErrorMessage InvalidDoLet =
437− line "Let statement cannot be the last statement in a do block. The last statement must be an expression."
438− renderSimpleErrorMessage CannotReorderOperators =
439− line "Unable to reorder operators"
440− renderSimpleErrorMessage UnspecifiedSkolemScope =
441− line "Skolem variable scope is unspecified"
424+ line "The last statement in a 'do' block must be an expression, but this block ends with a let binding."
442425 renderSimpleErrorMessage OverlappingNamesInLet =
443− line "Overlapping names in let binding."
426+ line "The same name was used more than once in a let binding."
444427 renderSimpleErrorMessage (InfiniteType ty) =
445428 paras [ line "An infinite type was inferred for an expression: "
446429 , indent $ typeAsBox ty
@@ -450,17 +433,17 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
450433 , indent $ line $ prettyPrintKind ki
451434 ]
452435 renderSimpleErrorMessage (MultipleFixities name) =
453− line $ "Multiple fixity declarations for " ++ showIdent name
436+ line $ "There are multiple fixity/precedence declarations for " ++ showIdent name
454437 renderSimpleErrorMessage (OrphanTypeDeclaration nm) =
455− line $ "Orphan type declaration for " ++ showIdent nm
438+ line $ "The type declaration for " ++ showIdent nm ++ " should be followed by its definition."
456439 renderSimpleErrorMessage (OrphanFixityDeclaration op) =
457− line $ "Orphan fixity declaration for " ++ show op
440+ line $ "The fixity/precedence declaration for " ++ show op ++ " should appear in the same module as its definition."
458441 renderSimpleErrorMessage (RedefinedModule name filenames) =
459− paras [ line ("Module " ++ runModuleName name ++ " has been defined multiple times:")
442+ paras [ line ("The module " ++ runModuleName name ++ " has been defined multiple times:")
460443 , indent . paras $ map (line . displaySourceSpan) filenames
461444 ]
462445 renderSimpleErrorMessage (RedefinedIdent name) =
463− line $ "Name " ++ showIdent name ++ " has been defined multiple times"
446+ line $ "The value " ++ showIdent name ++ " has been defined multiple times"
464447 renderSimpleErrorMessage (UnknownModule mn) =
465448 line $ "Unknown module " ++ runModuleName mn
466449 renderSimpleErrorMessage (UnknownType name) =
@@ -474,25 +457,36 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
474457 renderSimpleErrorMessage (UnknownDataConstructor dc tc) =
475458 line $ "Unknown data constructor " ++ showQualified runProperName dc ++ foldMap ((" for type constructor " ++) . showQualified runProperName) tc
476459 renderSimpleErrorMessage (UnknownImportType mn name) =
477− line $ "Module " ++ runModuleName mn ++ " does not export type " ++ runProperName name
460+ paras [ line $ "Cannot import type " ++ runProperName name ++ " from module " ++ runModuleName mn
461+ , line "It either does not exist or the module does not export it."
462+ ]
478463 renderSimpleErrorMessage (UnknownExportType name) =
479464 line $ "Cannot export unknown type " ++ runProperName name
480465 renderSimpleErrorMessage (UnknownImportTypeClass mn name) =
481− line $ "Module " ++ runModuleName mn ++ " does not export type class " ++ runProperName name
466+ paras [ line $ "Cannot import type class " ++ runProperName name ++ " from module " ++ runModuleName mn
467+ , line "It either does not exist or the module does not export it."
468+ ]
482469 renderSimpleErrorMessage (UnknownExportTypeClass name) =
483470 line $ "Cannot export unknown type class " ++ runProperName name
484471 renderSimpleErrorMessage (UnknownImportValue mn name) =
485− line $ "Module " ++ runModuleName mn ++ " does not export value " ++ showIdent name
472+ paras [ line $ "Cannot import value " ++ showIdent name ++ " from module " ++ runModuleName mn
473+ , line "It either does not exist or the module does not export it."
474+ ]
486475 renderSimpleErrorMessage (UnknownExportValue name) =
487476 line $ "Cannot export unknown value " ++ showIdent name
488477 renderSimpleErrorMessage (UnknownExportModule name) =
489− line $ "Cannot export unknown module " ++ runModuleName name ++ ", it either does not exist or has not been imported by the current module"
478+ paras [ line $ "Cannot export unknown module " ++ runModuleName name
479+ , line "It either does not exist or has not been imported by the current module."
480+ ]
490481 renderSimpleErrorMessage (UnknownImportDataConstructor mn tcon dcon) =
491482 line $ "Module " ++ runModuleName mn ++ " does not export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon
492483 renderSimpleErrorMessage (UnknownExportDataConstructor tcon dcon) =
493− line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ " as it has not been declared"
484+ line $ "Cannot export data constructor " ++ runProperName dcon ++ " for type " ++ runProperName tcon ++ ", as it has not been declared."
494485 renderSimpleErrorMessage (ConflictingImport nm mn) =
495− line $ "Cannot declare " ++ show nm ++ " since another declaration of that name was imported from " ++ runModuleName mn
486+ paras [ line $ "Cannot declare " ++ show nm ++ ", since another declaration of that name was imported from module " ++ runModuleName mn
487+ , line $ "Consider hiding " ++ show nm ++ " when importing " ++ runModuleName mn ++ ":"
488+ , indent . line $ "import " ++ runModuleName mn ++ " hiding (" ++ nm ++ ")"
489+ ]
496490 renderSimpleErrorMessage (ConflictingImports nm m1 m2) =
497491 line $ "Conflicting imports for " ++ nm ++ " from modules " ++ runModuleName m1 ++ " and " ++ runModuleName m2
498492 renderSimpleErrorMessage (ConflictingTypeDecls nm) =
@@ -500,13 +494,13 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
500494 renderSimpleErrorMessage (ConflictingCtorDecls nm) =
501495 line $ "Conflicting data constructor declarations for " ++ runProperName nm
502496 renderSimpleErrorMessage (TypeConflictsWithClass nm) =
503− line $ "Type " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
497+ line $ "Type " ++ runProperName nm ++ " conflicts with a type class declaration with the same name."
504498 renderSimpleErrorMessage (CtorConflictsWithClass nm) =
505− line $ "Data constructor " ++ runProperName nm ++ " conflicts with type class declaration of the same name"
499+ line $ "Data constructor " ++ runProperName nm ++ " conflicts with a type class declaration with the same name."
506500 renderSimpleErrorMessage (ClassConflictsWithType nm) =
507− line $ "Type class " ++ runProperName nm ++ " conflicts with type declaration of the same name"
501+ line $ "Type class " ++ runProperName nm ++ " conflicts with a type declaration with the same name."
508502 renderSimpleErrorMessage (ClassConflictsWithCtor nm) =
509− line $ "Type class " ++ runProperName nm ++ " conflicts with data constructor declaration of the same name"
503+ line $ "Type class " ++ runProperName nm ++ " conflicts with a data constructor declaration with the same name."
510504 renderSimpleErrorMessage (DuplicateModuleName mn) =
511505 line $ "Module " ++ runModuleName mn ++ " has been defined multiple times."
512506 renderSimpleErrorMessage (DuplicateClassExport nm) =
@@ -514,19 +508,24 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
514508 renderSimpleErrorMessage (DuplicateValueExport nm) =
515509 line $ "Duplicate export declaration for value " ++ showIdent nm
516510 renderSimpleErrorMessage (CycleInDeclaration nm) =
517− line $ "Cycle in declaration of " ++ showIdent nm
511+ line $ "The value of " ++ showIdent nm ++ " is undefined here, so this reference is not allowed."
518512 renderSimpleErrorMessage (CycleInModules mns) =
519− line $ "Cycle in module dependencies: " ++ intercalate ", " (map runModuleName mns)
520− renderSimpleErrorMessage (CycleInTypeSynonym pn) =
521− line $ "Cycle in type synonym" ++ foldMap ((" " ++) . runProperName) pn
513+ paras [ line $ "There is a cycle in module dependencies in these modules: "
514+ , indent $ paras (map (line . runModuleName) mns)
515+ ]
516+ renderSimpleErrorMessage (CycleInTypeSynonym name) =
517+ paras [ line $ case name of
518+ Just pn -> "A cycle appears in the definition of type synonym " ++ runProperName pn
519+ Nothing -> "A cycle appears in a set of type synonym definitions."
520+ , line "Cycles are disallowed because they can lead to loops in the type checker."
521+ , line "Consider using a 'newtype' instead."
522+ ]
522523 renderSimpleErrorMessage (NameIsUndefined ident) =
523− line $ showIdent ident ++ " is undefined"
524− renderSimpleErrorMessage (NameNotInScope ident) =
525− line $ showIdent ident ++ " may not be defined in the current scope"
524+ line $ "Value " ++ showIdent ident ++ " is undefined."
526525 renderSimpleErrorMessage (UndefinedTypeVariable name) =
527− line $ "Type variable " ++ runProperName name ++ " is undefined"
526+ line $ "Type variable " ++ runProperName name ++ " is undefined."
528527 renderSimpleErrorMessage (PartiallyAppliedSynonym name) =
529− paras [ line $ "Partially applied type synonym " ++ showQualified runProperName name
528+ paras [ line $ "Type synonym " ++ showQualified runProperName name ++ " is partially applied."
530529 , line "Type synonyms must be applied to all of their type arguments."
531530 ]
532531 renderSimpleErrorMessage (EscapedSkolem binding) =
@@ -535,70 +534,72 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
535534 , indent $ prettyPrintValue expr
536535 ]) binding
537536 renderSimpleErrorMessage (TypesDoNotUnify t1 t2)
538− = paras [ line "Cannot unify type"
537+ = paras [ line "Could not match expected type"
539538 , indent $ typeAsBox t1
540− , line "with type"
539+ , line "with actual type"
541540 , indent $ typeAsBox t2
542541 ]
543542 renderSimpleErrorMessage (KindsDoNotUnify k1 k2) =
544− paras [ line "Cannot unify kind"
543+ paras [ line "Could not match expected kind"
545544 , indent $ line $ prettyPrintKind k1
546− , line "with kind"
545+ , line "with actual kind"
547546 , indent $ line $ prettyPrintKind k2
548547 ]
549548 renderSimpleErrorMessage (ConstrainedTypeUnified t1 t2) =
550− paras [ line "Cannot unify constrained type"
549+ paras [ line "Could not match constrained type"
551550 , indent $ typeAsBox t1
552551 , line "with type"
553552 , indent $ typeAsBox t2
554553 ]
555554 renderSimpleErrorMessage (OverlappingInstances nm ts (d : ds)) =
556− paras [ line "Overlapping instances found for"
555+ paras [ line "Overlapping type class instances found for"
557556 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
558557 , Box.vcat Box.left (map typeAtomAsBox ts)
559558 ]
560559 , line "The following instances were found:"
561560 , indent $ paras (line (showQualified showIdent d ++ " (chosen)") : map (line . showQualified showIdent) ds)
561+ , line "Overlapping type class instances can lead to different behavior based on the order of module imports, and for that reason are not recommended."
562+ , line "They may be disallowed completely in a future version of the compiler."
562563 ]
563− renderSimpleErrorMessage OverlappingInstances{} = error "OverlappingInstances: empty instance list"
564+ renderSimpleErrorMessage OverlappingInstances{} = internalError "OverlappingInstances: empty instance list"
564565 renderSimpleErrorMessage (NoInstanceFound nm ts) =
565− paras [ line "No instance found for"
566+ paras [ line "No type class instance was found for"
566567 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
567568 , Box.vcat Box.left (map typeAtomAsBox ts)
568569 ]
569570 ]
570571 renderSimpleErrorMessage (PossiblyInfiniteInstance nm ts) =
571− paras [ line "Instance for"
572+ paras [ line "Type class instance for"
572573 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
573574 , Box.vcat Box.left (map typeAtomAsBox ts)
574575 ]
575576 , line "is possibly infinite."
576577 ]
577578 renderSimpleErrorMessage (CannotDerive nm ts) =
578− paras [ line "Cannot derive an instance for"
579+ paras [ line "Cannot derive a type class instance for"
579580 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName nm)
580581 , Box.vcat Box.left (map typeAtomAsBox ts)
581582 ]
582583 ]
583584 renderSimpleErrorMessage (CannotFindDerivingType nm) =
584− line $ "Cannot derive instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
585+ line $ "Cannot derive a type class instance, because the type declaration for " ++ runProperName nm ++ " could not be found."
585586 renderSimpleErrorMessage (DuplicateLabel l expr) =
586− paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
587+ paras $ [ line $ "Label " ++ show l ++ " appears more than once in a row type." ]
587588 <> foldMap (\expr' -> [ line "Relevant expression: "
588589 , indent $ prettyPrintValue expr'
589590 ]) expr
590591 renderSimpleErrorMessage (DuplicateTypeArgument name) =
591− line $ "Duplicate type argument " ++ show name
592+ line $ "Type argument " ++ show name ++ " appears more than once."
592593 renderSimpleErrorMessage (DuplicateValueDeclaration nm) =
593− line $ "Duplicate value declaration for " ++ showIdent nm
594+ line $ "Multiple value declarations exist for " ++ showIdent nm ++ "."
594595 renderSimpleErrorMessage (ArgListLengthsDiffer ident) =
595596 line $ "Argument list lengths differ in declaration " ++ showIdent ident
596597 renderSimpleErrorMessage (OverlappingArgNames ident) =
597598 line $ "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . showIdent) ident
598599 renderSimpleErrorMessage (MissingClassMember ident) =
599− line $ "Member " ++ showIdent ident ++ " has not been implemented"
600− renderSimpleErrorMessage (ExtraneousClassMember ident) =
601− line $ "Member " ++ showIdent ident ++ " is not a member of the class being instantiated"
600+ line $ "Type class member " ++ showIdent ident ++ " has not been implemented."
601+ renderSimpleErrorMessage (ExtraneousClassMember ident className) =
602+ line $ showIdent ident ++ " is not a member of type class " ++ showQualified runProperName className
602603 renderSimpleErrorMessage (ExpectedType ty kind) =
603604 paras [ line "In a type-annotated expression x :: t, the type t must have kind *."
604605 , line "The error arises from the type"
@@ -608,8 +609,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
608609 , line "instead."
609610 ]
610611 renderSimpleErrorMessage (IncorrectConstructorArity nm) =
611− line $ "Wrong number of arguments to constructor " ++ showQualified runProperName nm
612− renderSimpleErrorMessage SubsumptionCheckFailed = line "Unable to check type subsumption"
612+ line $ "Data constructor " ++ showQualified runProperName nm ++ " was given the wrong number of arguments in a case expression."
613613 renderSimpleErrorMessage (ExprDoesNotHaveType expr ty) =
614614 paras [ line "Expression"
615615 , indent $ prettyPrintValue expr
@@ -617,20 +617,20 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
617617 , indent $ typeAsBox ty
618618 ]
619619 renderSimpleErrorMessage (PropertyIsMissing prop row) =
620− paras [ line "Row"
620+ paras [ line "Row type"
621621 , indent $ prettyPrintRowWith '(' ')' row
622− , line $ "lacks required property " ++ show prop
622+ , line $ "lacks required label " ++ show prop
623623 ]
624624 renderSimpleErrorMessage (CannotApplyFunction fn arg) =
625− paras [ line "Cannot apply function of type"
625+ paras [ line "A function of type"
626626 , indent $ typeAsBox fn
627− , line "to argument"
627+ , line "can not be applied to the argument"
628628 , indent $ prettyPrintValue arg
629629 ]
630630 renderSimpleErrorMessage TypeSynonymInstance =
631− line "Type synonym instances are disallowed"
631+ line "Type class instances for type synonyms are disallowed."
632632 renderSimpleErrorMessage (OrphanInstance nm cnm ts) =
633− paras [ line $ "Instance " ++ showIdent nm ++ " for "
633+ paras [ line $ "Type class instance " ++ showIdent nm ++ " for "
634634 , indent $ Box.hsep 1 Box.left [ line (showQualified runProperName cnm)
635635 , Box.vcat Box.left (map typeAtomAsBox ts)
636636 ]
@@ -638,32 +638,37 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
638638 , line "An orphan instance is an instance which is defined in neither the class module nor the data type module."
639639 , line "Consider moving the instance, if possible, or using a newtype wrapper."
640640 ]
641− renderSimpleErrorMessage InvalidNewtype =
642− line "Newtypes must define a single constructor with a single argument"
641+ renderSimpleErrorMessage (InvalidNewtype name) =
642+ paras [ line $ "Newtype " ++ runProperName name ++ " is invalid."
643+ , line "Newtypes must define a single constructor with a single argument."
644+ ]
643645 renderSimpleErrorMessage (InvalidInstanceHead ty) =
644− paras [ line "Invalid type in class instance head:"
646+ paras [ line "Type class instance head is invalid due to use of type"
645647 , indent $ typeAsBox ty
648+ , 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."
646649 ]
647650 renderSimpleErrorMessage (TransitiveExportError x ys) =
648651 paras $ line ("An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: ")
649652 : map (line . prettyPrintExport) ys
650653 renderSimpleErrorMessage (ShadowedName nm) =
651− line $ "Name '" ++ showIdent nm ++ "' was shadowed"
654+ line $ "Name '" ++ showIdent nm ++ "' was shadowed."
652655 renderSimpleErrorMessage (ShadowedTypeVar tv) =
653− line $ "Type variable '" ++ tv ++ "' was shadowed"
656+ line $ "Type variable '" ++ tv ++ "' was shadowed."
654657 renderSimpleErrorMessage (UnusedTypeVar tv) =
655− line $ "Type variable '" ++ tv ++ "' was declared but not used"
658+ line $ "Type variable '" ++ tv ++ "' was declared but not used."
656659 renderSimpleErrorMessage (ClassOperator className opName) =
657− paras [ line $ "Class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
660+ paras [ line $ "Type class '" ++ runProperName className ++ "' declares operator " ++ showIdent opName ++ "."
658661 , line "This may be disallowed in the future - consider declaring a named member in the class and making the operator an alias:"
659662 , indent . line $ showIdent opName ++ " = someMember"
660663 ]
661664 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."
663666 renderSimpleErrorMessage (ImportHidingModule name) =
664− line $ "Attempted to hide module " ++ runModuleName name ++ " in import expression, this is not permitted"
667+ paras [ line $ "'hiding' imports cannot be used to hide modules."
668+ , line $ "An attempt was made to hide the import of " ++ runModuleName name
669+ ]
665670 renderSimpleErrorMessage (WildcardInferredType ty) =
666− paras [ line "The wildcard type definition has the inferred type "
671+ paras [ line "Wildcard type definition has the inferred type "
667672 , indent $ typeAsBox ty
668673 ]
669674 renderSimpleErrorMessage (MissingTypeDeclaration ident ty) =
@@ -692,7 +697,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
692697 renderHint (NotYetDefined names) =
693698 line $ "The following are not yet defined here: " ++ intercalate ", " (map showIdent names) ++ ":"
694699 renderHint (ErrorUnifyingTypes t1 t2) =
695− paras [ lineWithLevel "unifying type "
700+ paras [ lineWithLevel "while trying to match type "
696701 , indent $ typeAsBox t1
697702 , line "with type"
698703 , indent $ typeAsBox t2
@@ -705,9 +710,9 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
705710 paras [ lineWithLevel $ "in module " ++ runModuleName mn ++ ":"
706711 ]
707712 renderHint (ErrorInSubsumption t1 t2) =
708− paras [ lineWithLevel "checking that type "
713+ paras [ lineWithLevel "checking that type"
709714 , indent $ typeAsBox t1
710− , line "subsumes type"
715+ , line "is at least as general as type"
711716 , indent $ typeAsBox t2
712717 ]
713718 renderHint (ErrorInInstance nm ts) =
@@ -717,21 +722,21 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
717722 ]
718723 ]
719724 renderHint (ErrorCheckingKind ty) =
720− paras [ lineWithLevel "checking kind of type "
725+ paras [ lineWithLevel "checking kind of type"
721726 , indent $ typeAsBox ty
722727 ]
723728 renderHint (ErrorInferringType expr) =
724− paras [ lineWithLevel "inferring type of value "
729+ paras [ lineWithLevel "inferring type of expression"
725730 , indent $ prettyPrintValue expr
726731 ]
727732 renderHint (ErrorCheckingType expr ty) =
728− paras [ lineWithLevel "checking that value "
733+ paras [ lineWithLevel "checking that expression"
729734 , indent $ prettyPrintValue expr
730735 , line "has type"
731736 , indent $ typeAsBox ty
732737 ]
733738 renderHint (ErrorInApplication f t a) =
734− paras [ lineWithLevel "applying function"
739+ paras [ lineWithLevel "applying a function"
735740 , indent $ prettyPrintValue f
736741 , line "of type"
737742 , indent $ typeAsBox t
@@ -765,15 +770,6 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage . positionHintsFir
765770 Error -> "error"
766771 Warning -> "warning"
767772
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−
777773 paras :: [Box.Box] -> Box.Box
778774 paras = Box.vcat Box.left
779775
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
@@ -142,14 +143,14 @@ forall_ = mkPattern match
142143 match _ = Nothing
143144
144145typeAtomAsBox :: Type -> Box
145−typeAtomAsBox = fromMaybe (error "Incomplete pattern") . pattern matchTypeAtom () . insertPlaceholders
146+typeAtomAsBox = fromMaybe (internalError "Incomplete pattern") . pattern matchTypeAtom () . insertPlaceholders
146147
147148-- | Generate a pretty-printed string representing a Type, as it should appear inside parentheses
148149prettyPrintTypeAtom :: Type -> String
149150prettyPrintTypeAtom = render . typeAtomAsBox
150151
151152typeAsBox :: Type -> Box
152−typeAsBox = fromMaybe (error "Incomplete pattern") . pattern matchType () . insertPlaceholders
153+typeAsBox = fromMaybe (internalError "Incomplete pattern") . pattern matchType () . insertPlaceholders
153154
154155-- | Generate a pretty-printed string representing a Type
155156prettyPrintType :: 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 (const . throwError . errorMessage $ CannotReorderOperators) 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+9−8
@@ -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
@@ -289,18 +290,18 @@ typeInstanceDictionaryDeclaration name mn deps className tys decls =
289290
290291 memberToValue :: (Functor m, Applicative m, MonadSupply m, MonadError MultipleErrors m) => [(Ident, Type)] -> Declaration -> Desugar m Expr
291292 memberToValue tys' (ValueDeclaration ident _ [] (Right val)) = do
292− _ <- maybe (throwError . errorMessage $ ExtraneousClassMember ident) return $ lookup ident tys'
293+ _ <- maybe (throwError . errorMessage $ ExtraneousClassMember ident className) return $ lookup ident tys'
293294 return val
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/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−2
@@ -20,9 +20,9 @@ module Language.PureScript.TypeChecker.Subsumption (
2020import Data.List (sortBy)
2121import Data.Ord (comparing)
2222
23−import Control.Monad.Error.Class (MonadError(..))
2423import Control.Monad.Unify
2524
25+import Language.PureScript.Crash
2626import Language.PureScript.AST
2727import Language.PureScript.Environment
2828import Language.PureScript.Errors
@@ -50,7 +50,7 @@ subsumes' val ty1 (ForAll ident ty2 sco) =
5050 sko <- newSkolemConstant
5151 let sk = skolemize ident sko sco' ty2
5252 subsumes val ty1 sk
53− Nothing -> throwError . errorMessage $ UnspecifiedSkolemScope
53+ Nothing -> internalError "subsumes: unspecified skolem scope"
5454subsumes' val (TypeApp (TypeApp f1 arg1) ret1) (TypeApp (TypeApp f2 arg2) ret2) | f1 == tyFunction && f2 == tyFunction = do
5555 _ <- subsumes Nothing arg2 arg1
5656 _ <- subsumes Nothing ret1 ret2
src/Language/PureScript/TypeChecker/Types.hs+13−12
@@ -52,6 +52,7 @@ import Control.Monad.Unify
5252import Control.Monad.Error.Class (MonadError(..))
5353import Control.Monad.Writer.Class (tell)
5454
55+import Language.PureScript.Crash
5556import Language.PureScript.AST
5657import Language.PureScript.Environment
5758import Language.PureScript.Errors
@@ -140,7 +141,7 @@ typeForBindingGroupElement :: (Ident, Expr) -> TypeData -> UntypedData -> UnifyT
140141typeForBindingGroupElement (ident, val) dict untypedDict = do
141142 -- Infer the type with the new names in scope
142143 TypedValue _ val' ty <- bindNames dict $ infer val
143− ty =?= fromMaybe (error "name not found in dictionary") (lookup ident untypedDict)
144+ ty =?= fromMaybe (internalError "name not found in dictionary") (lookup ident untypedDict)
144145 tell . errorMessage $ MissingTypeDeclaration ident ty
145146 return (ident, (TypedValue True val' ty, ty))
146147
@@ -192,7 +193,7 @@ instantiatePolyTypeWithUnknowns val (ForAll ident ty _) = do
192193 instantiatePolyTypeWithUnknowns val ty'
193194instantiatePolyTypeWithUnknowns val (ConstrainedType constraints ty) = do
194195 dicts <- getTypeClassDictionaries
195− (_, ty') <- instantiatePolyTypeWithUnknowns (error "Types under a constraint cannot themselves be constrained") ty
196+ (_, ty') <- instantiatePolyTypeWithUnknowns (internalError "Types under a constraint cannot themselves be constrained") ty
196197 return (foldl App val (map (flip TypeClassDictionary dicts) constraints), ty')
197198instantiatePolyTypeWithUnknowns val ty = return (val, ty)
198199
@@ -242,7 +243,7 @@ infer' (Abs (Left arg) ret) = do
242243 withBindingGroupVisible $ bindLocalVariables moduleName [(arg, ty, Defined)] $ do
243244 body@(TypedValue _ _ bodyTy) <- infer' ret
244245 return $ TypedValue True (Abs (Left arg) body) $ function ty bodyTy
245−infer' (Abs (Right _) _) = error "Binder was not desugared"
246+infer' (Abs (Right _) _) = internalError "Binder was not desugared"
246247infer' (App f arg) = do
247248 f'@(TypedValue _ _ ft) <- infer f
248249 (ret, app) <- checkFunctionApplication f' ft arg Nothing
@@ -287,7 +288,7 @@ infer' (TypedValue checkType val ty) = do
287288 val' <- if checkType then withScopedTypeVars moduleName args (check val ty') else return val
288289 return $ TypedValue True val' ty'
289290infer' (PositionedValue pos _ val) = warnAndRethrowWithPosition pos $ infer' val
290−infer' _ = error "Invalid argument to infer"
291+infer' _ = internalError "Invalid argument to infer"
291292
292293inferLetBinding :: [Declaration] -> [Declaration] -> Expr -> (Expr -> UnifyT Type Check Expr) -> UnifyT Type Check ([Declaration], Expr)
293294inferLetBinding seen [] ret j = (,) seen <$> withBindingGroupVisible (j ret)
@@ -318,7 +319,7 @@ inferLetBinding seen (BindingGroupDeclaration ds : rest) ret j = do
318319inferLetBinding seen (PositionedDeclaration pos com d : ds) ret j = warnAndRethrowWithPosition pos $ do
319320 (d' : ds', val') <- inferLetBinding seen (d : ds) ret j
320321 return (PositionedDeclaration pos com d' : ds', val')
321−inferLetBinding _ _ _ _ = error "Invalid argument to inferLetBinding"
322+inferLetBinding _ _ _ _ = internalError "Invalid argument to inferLetBinding"
322323
323324-- |
324325-- Infer the types of variables brought into scope by a binder
@@ -335,7 +336,7 @@ inferBinder val (ConstructorBinder ctor binders) = do
335336 env <- getEnv
336337 case M.lookup ctor (dataConstructors env) of
337338 Just (_, _, ty, _) -> do
338− (_, fn) <- instantiatePolyTypeWithUnknowns (error "Data constructor types cannot contain constraints") ty
339+ (_, fn) <- instantiatePolyTypeWithUnknowns (internalError "Data constructor types cannot contain constraints") ty
339340 fn' <- introduceSkolemScope <=< replaceAllTypeSynonyms $ fn
340341 go binders fn'
341342 where
@@ -454,7 +455,7 @@ check' val t@(ConstrainedType constraints ty) = do
454455 newDictionaries :: [(Qualified ProperName, Integer)] -> Qualified Ident -> (Qualified ProperName, [Type]) -> Check [TypeClassDictionaryInScope]
455456 newDictionaries path name (className, instanceTy) = do
456457 tcs <- gets (typeClasses . checkEnv)
457− let (args, _, superclasses) = fromMaybe (error "newDictionaries: type class lookup failed") $ M.lookup className tcs
458+ let (args, _, superclasses) = fromMaybe (internalError "newDictionaries: type class lookup failed") $ M.lookup className tcs
458459 supDicts <- join <$> zipWithM (\(supName, supArgs) index ->
459460 newDictionaries ((supName, index) : path)
460461 name
@@ -489,7 +490,7 @@ check' (Abs (Left arg) ret) ty@(TypeApp (TypeApp t argTy) retTy) = do
489490 Just moduleName <- checkCurrentModule <$> get
490491 ret' <- withBindingGroupVisible $ bindLocalVariables moduleName [(arg, argTy, Defined)] $ check ret retTy
491492 return $ TypedValue True (Abs (Left arg) ret') ty
492−check' (Abs (Right _) _) _ = error "Binder was not desugared"
493+check' (Abs (Right _) _) _ = internalError "Binder was not desugared"
493494check' (App f arg) ret = do
494495 f'@(TypedValue _ _ ft) <- infer f
495496 (_, app) <- checkFunctionApplication f' ft arg (Just ret)
@@ -501,7 +502,7 @@ check' v@(Var var) ty = do
501502 ty' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty
502503 v' <- subsumes (Just v) repl ty'
503504 case v' of
504− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
505+ Nothing -> internalError "check: unable to check the subsumes relation."
505506 Just v'' -> return $ TypedValue True v'' ty'
506507check' (SuperClassDictionary className tys) _ = do
507508 {-
@@ -520,7 +521,7 @@ check' (TypedValue checkType val ty1) ty2 = do
520521 ty2' <- introduceSkolemScope <=< replaceAllTypeSynonyms <=< replaceTypeWildcards $ ty2
521522 val' <- subsumes (Just val) ty1' ty2'
522523 case val' of
523− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
524+ Nothing -> internalError "check: unable to check the subsumes relation."
524525 Just _ -> do
525526 val''' <- if checkType then withScopedTypeVars moduleName args (check val ty2') else return val
526527 return $ TypedValue checkType val''' ty2'
@@ -562,7 +563,7 @@ check' v@(Constructor c) ty = do
562563 repl <- introduceSkolemScope <=< replaceAllTypeSynonyms $ ty1
563564 mv <- subsumes (Just v) repl ty
564565 case mv of
565− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
566+ Nothing -> internalError "check: unable to check the subsumes relation."
566567 Just v' -> return $ TypedValue True v' ty
567568check' (Let ds val) ty = do
568569 (ds', val') <- inferLetBinding [] ds val (`check` ty)
@@ -577,7 +578,7 @@ check' val ty = do
577578 TypedValue _ val' ty' <- infer val
578579 mt <- subsumes (Just val') ty' ty
579580 case mt of
580− Nothing -> throwError . errorMessage $ SubsumptionCheckFailed
581+ Nothing -> internalError "check: unable to check the subsumes relation."
581582 Just v' -> return $ TypedValue True v' ty
582583
583584-- |
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 "Skolemized type variable was not given a 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{} _ = throwError . errorMessage $ UnspecifiedSkolemScope
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" []