@@ -59,9 +59,20 @@ data ErrorMessage
5959 | ClassConflictsWithCtor ProperName
6060 | DuplicateClassExport ProperName
6161 | DuplicateValueExport Ident
62+ | InvalidDoBind
63+ | InvalidDoLet
64+ | CycleInDeclaration Ident
65+ | CycleInTypeSynonym (Maybe ProperName)
66+ | NameIsUndefined Ident
67+ | NameNotInScope Ident
68+ | UndefinedTypeVariable ProperName
69+ | PartiallyAppliedSynonym (Qualified ProperName)
70+ | NotYetDefined [Ident] ErrorMessage
71+ | EscapedSkolem (Maybe Expr)
72+ | ErrorInExpression Expr ErrorMessage
6273 | ErrorInModule ModuleName ErrorMessage
6374 | PositionedError SourceSpan ErrorMessage
64− deriving (Show, Eq)
75+ deriving (Show)
6576
6677instance UnificationError Type ErrorMessage where
6778 occursCheckFailed = InfiniteType
@@ -73,6 +84,8 @@ instance UnificationError Kind ErrorMessage where
7384-- Pretty print an ErrorMessage
7485--
7586prettyPrintErrorMessage :: ErrorMessage -> String
87+prettyPrintErrorMessage InvalidDoBind = "Bind statement cannot be the last statement in a do block"
88+prettyPrintErrorMessage InvalidDoLet = "Let statement cannot be the last statement in a do block"
7689prettyPrintErrorMessage CannotReorderOperators = "Unable to reorder operators"
7790prettyPrintErrorMessage OverlappingNamesInLet = "Overlapping names in let binding."
7891prettyPrintErrorMessage (InfiniteType ty) = "Infinite type detected: " ++ prettyPrintType ty
@@ -95,14 +108,23 @@ prettyPrintErrorMessage (ClassConflictsWithType nm) = "Type class " ++ show
95108prettyPrintErrorMessage (ClassConflictsWithCtor nm) = "Type class " ++ show nm ++ " conflicts with data constructor declaration of the same name"
96109prettyPrintErrorMessage (DuplicateClassExport nm) = "Duplicate export declaration for type class " ++ show nm
97110prettyPrintErrorMessage (DuplicateValueExport nm) = "Duplicate export declaration for value " ++ show nm
98−prettyPrintErrorMessage (ErrorInModule mn err) = "Error in module " ++ show mn ++ ": " ++ prettyPrintErrorMessage err
99−prettyPrintErrorMessage (PositionedError pos err) = "Error at " ++ show pos ++ ": \n" ++ prettyPrintErrorMessage err
111+prettyPrintErrorMessage (CycleInDeclaration nm) = "Cycle in declaration of " ++ show nm
112+prettyPrintErrorMessage (NotYetDefined names err) = "The following are not yet defined here: " ++ unwords (map show names) ++ "\n" ++ prettyPrintErrorMessage err
113+prettyPrintErrorMessage (CycleInTypeSynonym pn) = "Cycle in type synonym" ++ foldMap ((" " ++) . show) pn
114+prettyPrintErrorMessage (NameIsUndefined ident) = show ident ++ " is undefined"
115+prettyPrintErrorMessage (NameNotInScope ident) = show ident ++ " may not be defined in the current scope"
116+prettyPrintErrorMessage (UndefinedTypeVariable name) = "Type variable " ++ show name ++ " is undefined"
117+prettyPrintErrorMessage (PartiallyAppliedSynonym name) = "Partially applied type synonym " ++ show name
118+prettyPrintErrorMessage (EscapedSkolem binding) = "Rigid/skolem type variable " ++ foldMap (("bound by " ++) . prettyPrintValue) binding ++ " has escaped."
119+prettyPrintErrorMessage (ErrorInExpression expr err) = "Error in expression " ++ prettyPrintValue expr ++ ":\n" ++ prettyPrintErrorMessage err
120+prettyPrintErrorMessage (ErrorInModule mn err) = "Error in module " ++ show mn ++ ":\n" ++ prettyPrintErrorMessage err
121+prettyPrintErrorMessage (PositionedError pos err) = "Error at " ++ show pos ++ ":\n" ++ prettyPrintErrorMessage err
100122
101123-- |
102124-- A stack trace for an error
103125--
104126newtype MultipleErrors = MultipleErrors
105− { runMultipleErrors :: [ErrorMessage] } deriving (Show, Eq, Monoid)
127+ { runMultipleErrors :: [ErrorMessage] } deriving (Show, Monoid)
106128
107129-- |
108130-- Simplify an error message
@@ -111,7 +133,9 @@ simplifyErrorMessage :: ErrorMessage -> ErrorMessage
111133simplifyErrorMessage = unwrap Nothing
112134 where
113135 unwrap :: Maybe SourceSpan -> ErrorMessage -> ErrorMessage
136+ unwrap pos (ErrorInExpression _ err) = unwrap pos err
114137 unwrap pos (ErrorInModule mn err) = ErrorInModule mn (unwrap pos err)
138+ unwrap pos (NotYetDefined ns err) = NotYetDefined ns (unwrap pos err)
115139 unwrap _ (PositionedError pos err) = unwrap (Just pos) err
116140 unwrap pos other = wrap pos other
117141