Skip to content

Commit bc763b7

Browse files
committed
1 parent 03fc48b commit bc763b7

2 files changed

Lines changed: 90 additions & 52 deletions

File tree

src/Language/PureScript/Errors.hs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
module Language.PureScript.Errors where
2020

2121
import Data.Either (lefts, rights)
22-
import Data.List (intersperse)
22+
import Data.List (intersperse, intercalate)
2323
import Data.Monoid
2424
import Data.Foldable (fold, foldMap)
2525

@@ -43,7 +43,9 @@ data ErrorMessage
4343
| CannotReorderOperators
4444
| MultipleFixities Ident
4545
| OrphanTypeDeclaration Ident
46+
| OrphanFixityDeclaration String
4647
| RedefinedModule ModuleName
48+
| RedefinedIdent Ident
4749
| OverlappingNamesInLet
4850
| UnknownModule ModuleName
4951
| UnknownType (Qualified ProperName)
@@ -61,6 +63,7 @@ data ErrorMessage
6163
| ClassConflictsWithCtor ProperName
6264
| DuplicateClassExport ProperName
6365
| DuplicateValueExport Ident
66+
| DuplicateTypeArgument String
6467
| InvalidDoBind
6568
| InvalidDoLet
6669
| CycleInDeclaration Ident
@@ -89,6 +92,10 @@ data ErrorMessage
8992
| PropertyIsMissing String Type
9093
| ErrorUnifyingTypes Type Type ErrorMessage
9194
| CannotApplyFunction Type Expr
95+
| TypeSynonymInstance
96+
| InvalidNewtype
97+
| InvalidInstanceHead Type
98+
| TransitiveExportError DeclarationRef [DeclarationRef]
9299
| ErrorInExpression Expr ErrorMessage
93100
| ErrorInModule ModuleName ErrorMessage
94101
| ErrorInInstance (Qualified ProperName) [Type] ErrorMessage
@@ -97,6 +104,13 @@ data ErrorMessage
97104
| ErrorCheckingKind Type ErrorMessage
98105
| ErrorInferringType Expr ErrorMessage
99106
| ErrorInApplication Expr Type Expr ErrorMessage
107+
| ErrorInDataConstructor ProperName ErrorMessage
108+
| ErrorInTypeConstructor ProperName ErrorMessage
109+
| ErrorInBindingGroup [Ident] ErrorMessage
110+
| ErrorInDataBindingGroup ErrorMessage
111+
| ErrorInTypeSynonym ProperName ErrorMessage
112+
| ErrorInValueDeclaration Ident ErrorMessage
113+
| ErrorInForeignImport Ident ErrorMessage
100114
| PositionedError SourceSpan ErrorMessage
101115
deriving (Show)
102116

@@ -118,8 +132,10 @@ prettyPrintErrorMessage OverlappingNamesInLet = "Overlapping names in
118132
prettyPrintErrorMessage (InfiniteType ty) = "Infinite type detected: " ++ prettyPrintType ty
119133
prettyPrintErrorMessage (InfiniteKind ki) = "Infinite kind detected: " ++ prettyPrintKind ki
120134
prettyPrintErrorMessage (MultipleFixities name) = "Multiple fixity declarations for " ++ show name
121-
prettyPrintErrorMessage (OrphanTypeDeclaration pn) = "Orphan type declaration for: " ++ show pn
135+
prettyPrintErrorMessage (OrphanTypeDeclaration nm) = "Orphan type declaration for " ++ show nm
136+
prettyPrintErrorMessage (OrphanFixityDeclaration op) = "Orphan fixity declaration for " ++ show op
122137
prettyPrintErrorMessage (RedefinedModule name) = "Module " ++ show name ++ " has been defined multiple times"
138+
prettyPrintErrorMessage (RedefinedIdent name) = "Name " ++ show name ++ " has been defined multiple times"
123139
prettyPrintErrorMessage (UnknownModule mn) = "Unknown module " ++ show mn
124140
prettyPrintErrorMessage (UnknownType name) = "Unknown type " ++ show name
125141
prettyPrintErrorMessage (UnknownTypeClass name) = "Unknown type class " ++ show name
@@ -151,6 +167,7 @@ prettyPrintErrorMessage (OverlappingInstances nm ts ds) = unlines (("Overlapping
151167
: map prettyPrintDictionaryValue ds)
152168
prettyPrintErrorMessage (NoInstanceFound nm ts) = "No instance found for " ++ show nm ++ " " ++ unwords (map prettyPrintTypeAtom ts)
153169
prettyPrintErrorMessage (DuplicateLabel l expr) = "Duplicate label " ++ show l ++ " in row." ++ foldMap ((" Relevant expression: " ++) . prettyPrintValue) expr
170+
prettyPrintErrorMessage (DuplicateTypeArgument name) = "Duplicate type argument " ++ show name
154171
prettyPrintErrorMessage (DuplicateValueDeclaration nm) = "Duplicate value declaration for " ++ show nm
155172
prettyPrintErrorMessage (ArgListLengthsDiffer ident) = "Argument list lengths differ in declaration " ++ show ident
156173
prettyPrintErrorMessage (OverlappingArgNames ident) = "Overlapping names in function/binder" ++ foldMap ((" in declaration" ++) . show) ident
@@ -161,6 +178,10 @@ prettyPrintErrorMessage SubsumptionCheckFailed = "Unable to check type
161178
prettyPrintErrorMessage (ExprDoesNotHaveType expr ty) = "Expression " ++ prettyPrintValue expr ++ " does not have type " ++ prettyPrintType ty
162179
prettyPrintErrorMessage (PropertyIsMissing prop row) = "Row " ++ prettyPrintRow row ++ " lacks required property " ++ show prop
163180
prettyPrintErrorMessage (CannotApplyFunction fn arg) = "Cannot apply function of type " ++ prettyPrintType fn ++ " to argument " ++ prettyPrintValue arg
181+
prettyPrintErrorMessage TypeSynonymInstance = "Type synonym instances are disallowed"
182+
prettyPrintErrorMessage InvalidNewtype = "Newtypes must define a single constructor with a single argument"
183+
prettyPrintErrorMessage (InvalidInstanceHead ty) = "Invalid type " ++ prettyPrintType ty ++ " in class instance head"
184+
prettyPrintErrorMessage (TransitiveExportError x ys) = "An export for " ++ prettyPrintExport x ++ " requires the following to also be exported: " ++ intercalate ", " (map prettyPrintExport ys)
164185
prettyPrintErrorMessage (ErrorUnifyingTypes t1 t2 err) = "Error unifying type " ++ prettyPrintType t1 ++ " with type " ++ prettyPrintType t2 ++ ":\n" ++ prettyPrintErrorMessage err
165186
prettyPrintErrorMessage (ErrorInExpression expr err) = "Error in expression " ++ prettyPrintValue expr ++ ":\n" ++ prettyPrintErrorMessage err
166187
prettyPrintErrorMessage (ErrorInModule mn err) = "Error in module " ++ show mn ++ ":\n" ++ prettyPrintErrorMessage err
@@ -170,6 +191,13 @@ prettyPrintErrorMessage (ErrorCheckingKind ty err) = "Error checking kind o
170191
prettyPrintErrorMessage (ErrorInferringType expr err) = "Error inferring type of value " ++ prettyPrintValue expr ++ ":\n" ++ prettyPrintErrorMessage err
171192
prettyPrintErrorMessage (ErrorCheckingType expr ty err) = "Error checking value " ++ prettyPrintValue expr ++ " has type " ++ prettyPrintType ty ++ ":\n" ++ prettyPrintErrorMessage err
172193
prettyPrintErrorMessage (ErrorInApplication f t a err) = "Error applying function " ++ prettyPrintValue f ++ " of type " ++ prettyPrintType t ++ " to argument " ++ prettyPrintValue a ++ ":\n" ++ prettyPrintErrorMessage err
194+
prettyPrintErrorMessage (ErrorInDataConstructor nm err) = "Error in data constructor " ++ show nm ++ ":\n" ++ prettyPrintErrorMessage err
195+
prettyPrintErrorMessage (ErrorInTypeConstructor nm err) = "Error in type constructor " ++ show nm ++ ":\n" ++ prettyPrintErrorMessage err
196+
prettyPrintErrorMessage (ErrorInBindingGroup nms err) = "Error in binding group " ++ intercalate ", " (map show nms) ++ ":\n" ++ prettyPrintErrorMessage err
197+
prettyPrintErrorMessage (ErrorInDataBindingGroup err) = "Error in data binding group:\n" ++ prettyPrintErrorMessage err
198+
prettyPrintErrorMessage (ErrorInTypeSynonym name err) = "Error in type synonym " ++ show name ++ ":\n" ++ prettyPrintErrorMessage err
199+
prettyPrintErrorMessage (ErrorInValueDeclaration n err) = "Error in value declaration " ++ show n ++ ":\n" ++ prettyPrintErrorMessage err
200+
prettyPrintErrorMessage (ErrorInForeignImport nm err) = "Error in foreign import " ++ show nm ++ ":\n" ++ prettyPrintErrorMessage err
173201
prettyPrintErrorMessage (PositionedError pos err) = "Error at " ++ show pos ++ ":\n" ++ prettyPrintErrorMessage err
174202

175203
-- |
@@ -185,6 +213,16 @@ prettyPrintDictionaryValue = unlines . indented 0
185213

186214
spaces n = replicate n ' ' ++ "- "
187215

216+
-- |
217+
-- Pretty print and export declaration
218+
--
219+
prettyPrintExport :: DeclarationRef -> String
220+
prettyPrintExport (TypeRef pn _) = show pn
221+
prettyPrintExport (ValueRef ident) = show ident
222+
prettyPrintExport (TypeClassRef pn) = show pn
223+
prettyPrintExport (TypeInstanceRef ident) = show ident
224+
prettyPrintExport (PositionedDeclarationRef _ _ ref) = prettyPrintExport ref
225+
188226
-- |
189227
-- A stack trace for an error
190228
--
@@ -212,6 +250,14 @@ simplifyErrorMessage = unwrap Nothing
212250
unwrap pos (ErrorCheckingType _ _ err) = unwrap pos err
213251
unwrap pos (ErrorCheckingKind ty err) = ErrorCheckingKind ty (unwrap pos err)
214252
unwrap pos (ErrorInModule mn err) = ErrorInModule mn (unwrap pos err)
253+
unwrap pos (ErrorInApplication _ _ _ err) = unwrap pos err
254+
unwrap pos (ErrorInDataConstructor nm err) = ErrorInDataConstructor nm (unwrap pos err)
255+
unwrap pos (ErrorInTypeConstructor nm err) = ErrorInTypeConstructor nm (unwrap pos err)
256+
unwrap pos (ErrorInBindingGroup nms err) = ErrorInBindingGroup nms (unwrap pos err)
257+
unwrap pos (ErrorInDataBindingGroup err) = ErrorInDataBindingGroup (unwrap pos err)
258+
unwrap pos (ErrorInTypeSynonym nm err) = ErrorInTypeSynonym nm (unwrap pos err)
259+
unwrap pos (ErrorInValueDeclaration nm err) = ErrorInValueDeclaration nm (unwrap pos err)
260+
unwrap pos (ErrorInForeignImport nm err) = ErrorInForeignImport nm (unwrap pos err)
215261
unwrap pos (NotYetDefined ns err) = NotYetDefined ns (unwrap pos err)
216262
unwrap _ (PositionedError pos err) = unwrap (Just pos) err
217263
unwrap pos other = wrap pos other

0 commit comments

Comments
 (0)