@@ -32,6 +32,7 @@ import Language.PureScript.Pretty
32import Language.PureScript.Types
32import Language.PureScript.Types
33import Language.PureScript.Names
33import Language.PureScript.Names
34import Language.PureScript.Kinds
34import Language.PureScript.Kinds
35+import Language.PureScript.TypeClassDictionaries
37-- A type of error messages
38-- A type of error messages
@@ -49,6 +50,7 @@ data ErrorMessage
49 | UnknownTypeClass (Qualified ProperName)
50 | UnknownTypeClass (Qualified ProperName)
50 | UnknownValue (Qualified Ident)
51 | UnknownValue (Qualified Ident)
51 | UnknownDataConstructor (Qualified ProperName) (Maybe (Qualified ProperName))
52 | UnknownDataConstructor (Qualified ProperName) (Maybe (Qualified ProperName))
53+ | UnknownTypeConstructor (Qualified ProperName)
52 | ConflictingImport String ModuleName
54 | ConflictingImport String ModuleName
53 | ConflictingImports String ModuleName ModuleName
55 | ConflictingImports String ModuleName ModuleName
54 | ConflictingTypeDecls ProperName
56 | ConflictingTypeDecls ProperName
@@ -69,8 +71,23 @@ data ErrorMessage
69 | PartiallyAppliedSynonym (Qualified ProperName)
71 | PartiallyAppliedSynonym (Qualified ProperName)
70 | NotYetDefined [Ident] ErrorMessage
72 | NotYetDefined [Ident] ErrorMessage
71 | EscapedSkolem (Maybe Expr)
73 | EscapedSkolem (Maybe Expr)
74+ | UnspecifiedSkolemScope
75+ | TypesDoNotUnify Type Type
76+ | KindsDoNotUnify Kind Kind
77+ | ConstrainedTypeUnified Type Type
78+ | OverlappingInstances (Qualified ProperName) [Type] [DictionaryValue]
79+ | NoInstanceFound (Qualified ProperName) [Type]
80+ | DuplicateLabel String Expr
81+ | DuplicateValueDeclaration Ident
82+ | ArgListLengthsDiffer Ident
83+ | OverlappingArgNames Ident
84+ | MissingClassMember Ident
85+ | ErrorUnifyingTypes Type Type ErrorMessage
72 | ErrorInExpression Expr ErrorMessage
86 | ErrorInExpression Expr ErrorMessage
73 | ErrorInModule ModuleName ErrorMessage
87 | ErrorInModule ModuleName ErrorMessage
88+ | ErrorInInstance (Qualified ProperName) [Type] ErrorMessage
89+ | ErrorInSubsumption Type Type ErrorMessage
90+ | ErrorCheckingKind Type ErrorMessage
74 | PositionedError SourceSpan ErrorMessage
91 | PositionedError SourceSpan ErrorMessage
75 deriving (Show)
92 deriving (Show)
@@ -87,16 +104,18 @@ prettyPrintErrorMessage :: ErrorMessage -> String
87prettyPrintErrorMessage InvalidDoBind = "Bind statement cannot be the last statement in a do block"
104prettyPrintErrorMessage InvalidDoBind = "Bind statement cannot be the last statement in a do block"
88prettyPrintErrorMessage InvalidDoLet = "Let statement cannot be the last statement in a do block"
105prettyPrintErrorMessage InvalidDoLet = "Let statement cannot be the last statement in a do block"
89prettyPrintErrorMessage CannotReorderOperators = "Unable to reorder operators"
106prettyPrintErrorMessage CannotReorderOperators = "Unable to reorder operators"
107+prettyPrintErrorMessage UnspecifiedSkolemScope = "Skolem variable scope is unspecified"
90prettyPrintErrorMessage OverlappingNamesInLet = "Overlapping names in let binding."
108prettyPrintErrorMessage OverlappingNamesInLet = "Overlapping names in let binding."
91prettyPrintErrorMessage (InfiniteType ty) = "Infinite type detected: " ++ prettyPrintType ty
109prettyPrintErrorMessage (InfiniteType ty) = "Infinite type detected: " ++ prettyPrintType ty
92prettyPrintErrorMessage (InfiniteKind ki) = "Infinite kind detected: " ++ prettyPrintKind ki
110prettyPrintErrorMessage (InfiniteKind ki) = "Infinite kind detected: " ++ prettyPrintKind ki
93prettyPrintErrorMessage (MultipleFixities name) = "Multiple fixity declarations for " ++ show name
111prettyPrintErrorMessage (MultipleFixities name) = "Multiple fixity declarations for " ++ show name
94prettyPrintErrorMessage (OrphanTypeDeclaration pn) = "Orphan type declaration for: " ++ show pn
112prettyPrintErrorMessage (OrphanTypeDeclaration pn) = "Orphan type declaration for: " ++ show pn
95prettyPrintErrorMessage (RedefinedModule name) = "Module " ++ show name ++ " has been defined multiple times"
113prettyPrintErrorMessage (RedefinedModule name) = "Module " ++ show name ++ " has been defined multiple times"
96−prettyPrintErrorMessage (UnknownModule mn) = "Unknown module: " ++ show mn
114+prettyPrintErrorMessage (UnknownModule mn) = "Unknown module " ++ show mn
97−prettyPrintErrorMessage (UnknownType name) = "Unknown type: " ++ show name
115+prettyPrintErrorMessage (UnknownType name) = "Unknown type " ++ show name
98−prettyPrintErrorMessage (UnknownTypeClass name) = "Unknown type class: " ++ show name
116+prettyPrintErrorMessage (UnknownTypeClass name) = "Unknown type class " ++ show name
99−prettyPrintErrorMessage (UnknownValue name) = "Unknown value: " ++ show name
117+prettyPrintErrorMessage (UnknownValue name) = "Unknown value " ++ show name
118+prettyPrintErrorMessage (UnknownTypeConstructor name) = "Unknown type constructor " ++ show name
100prettyPrintErrorMessage (UnknownDataConstructor dc tc) = "Unknown data constructor " ++ show dc ++ foldMap ((" for type constructor " ++) . show) tc
119prettyPrintErrorMessage (UnknownDataConstructor dc tc) = "Unknown data constructor " ++ show dc ++ foldMap ((" for type constructor " ++) . show) tc
101prettyPrintErrorMessage (ConflictingImport nm mn) = "Declaration " ++ nm ++ " conflicts with import " ++ show mn
120prettyPrintErrorMessage (ConflictingImport nm mn) = "Declaration " ++ nm ++ " conflicts with import " ++ show mn
102prettyPrintErrorMessage (ConflictingImports nm m1 m2) = "Conflicting imports for " ++ nm ++ " from modules " ++ show m1 ++ " and " ++ show m2
121prettyPrintErrorMessage (ConflictingImports nm m1 m2) = "Conflicting imports for " ++ nm ++ " from modules " ++ show m1 ++ " and " ++ show m2
@@ -116,15 +135,49 @@ prettyPrintErrorMessage (NameNotInScope ident) = show ident ++ " may no
116prettyPrintErrorMessage (UndefinedTypeVariable name) = "Type variable " ++ show name ++ " is undefined"
135prettyPrintErrorMessage (UndefinedTypeVariable name) = "Type variable " ++ show name ++ " is undefined"
117prettyPrintErrorMessage (PartiallyAppliedSynonym name) = "Partially applied type synonym " ++ show name
136prettyPrintErrorMessage (PartiallyAppliedSynonym name) = "Partially applied type synonym " ++ show name
118prettyPrintErrorMessage (EscapedSkolem binding) = "Rigid/skolem type variable " ++ foldMap (("bound by " ++) . prettyPrintValue) binding ++ " has escaped."
137prettyPrintErrorMessage (EscapedSkolem binding) = "Rigid/skolem type variable " ++ foldMap (("bound by " ++) . prettyPrintValue) binding ++ " has escaped."
138+prettyPrintErrorMessage (TypesDoNotUnify t1 t2) = "Cannot unify " ++ prettyPrintType t1 ++ " with " ++ prettyPrintType t2
139+prettyPrintErrorMessage (KindsDoNotUnify k1 k2) = "Cannot unify " ++ prettyPrintKind k1 ++ " with " ++ prettyPrintKind k2
140+prettyPrintErrorMessage (ConstrainedTypeUnified t1 t2) = "Cannot unify constrained type " ++ prettyPrintType t1 ++ " with " ++ prettyPrintType t2
141+prettyPrintErrorMessage (OverlappingInstances nm ts ds) = unlines (("Overlapping instances found for " ++ show nm ++ " " ++ unwords (map prettyPrintType ts) ++ ":")
142+ : map prettyPrintDictionaryValue ds)
143+prettyPrintErrorMessage (NoInstanceFound nm ts) = "No instance found for " ++ show nm ++ " " ++ unwords (map prettyPrintTypeAtom ts)
144+prettyPrintErrorMessage (DuplicateLabel l expr) = "Duplicate label " ++ show l ++ " in row. Relevant expression: " ++ prettyPrintValue expr
145+prettyPrintErrorMessage (DuplicateValueDeclaration nm) = "Duplicate value declaration for " ++ show nm
146+prettyPrintErrorMessage (ArgListLengthsDiffer ident) = "Argument list lengths differ in declaration " ++ show ident
147+prettyPrintErrorMessage (OverlappingArgNames ident) = "Overlapping function argument names in declaration" ++ show ident
148+prettyPrintErrorMessage (MissingClassMember ident) = "Member " ++ show ident ++ " has not been implemented"
149+prettyPrintErrorMessage (ErrorUnifyingTypes t1 t2 err) = "Error unifying type " ++ prettyPrintType t1 ++ " with type " ++ prettyPrintType t2 ++ ":\n" ++ prettyPrintErrorMessage err
119prettyPrintErrorMessage (ErrorInExpression expr err) = "Error in expression " ++ prettyPrintValue expr ++ ":\n" ++ prettyPrintErrorMessage err
150prettyPrintErrorMessage (ErrorInExpression expr err) = "Error in expression " ++ prettyPrintValue expr ++ ":\n" ++ prettyPrintErrorMessage err
120prettyPrintErrorMessage (ErrorInModule mn err) = "Error in module " ++ show mn ++ ":\n" ++ prettyPrintErrorMessage err
151prettyPrintErrorMessage (ErrorInModule mn err) = "Error in module " ++ show mn ++ ":\n" ++ prettyPrintErrorMessage err
152+prettyPrintErrorMessage (ErrorInSubsumption t1 t2 err) = "Error checking that type " ++ prettyPrintType t1 ++ " subsumes type " ++ prettyPrintType t2 ++ ":\n" ++ prettyPrintErrorMessage err
153+prettyPrintErrorMessage (ErrorInInstance name ts err) = "Error in type class instance " ++ show name ++ " " ++ unwords (map prettyPrintTypeAtom ts) ++ ":\n" ++ prettyPrintErrorMessage err
154+prettyPrintErrorMessage (ErrorCheckingKind ty err) = "Error checking kind of type " ++ prettyPrintType ty ++ ":\n" ++ prettyPrintErrorMessage err
121prettyPrintErrorMessage (PositionedError pos err) = "Error at " ++ show pos ++ ":\n" ++ prettyPrintErrorMessage err
155prettyPrintErrorMessage (PositionedError pos err) = "Error at " ++ show pos ++ ":\n" ++ prettyPrintErrorMessage err
158+-- Render a DictionaryValue fit for human consumption in error messages
160+prettyPrintDictionaryValue :: DictionaryValue -> String
161+prettyPrintDictionaryValue = unlines . indented 0
163+ indented n (LocalDictionaryValue _) = [spaces n ++ "Dictionary in scope"]
164+ indented n (GlobalDictionaryValue nm) = [spaces n ++ show nm]
165+ indented n (DependentDictionaryValue nm args) = (spaces n ++ show nm ++ " via") : concatMap (indented (n + 2)) args
166+ indented n (SubclassDictionaryValue sup nm _) = (spaces n ++ show nm ++ " via superclass") : indented (n + 2) sup
168+ spaces n = replicate n ' ' ++ "- "
124-- A stack trace for an error
171-- A stack trace for an error
126newtype MultipleErrors = MultipleErrors
173newtype MultipleErrors = MultipleErrors
127 { runMultipleErrors :: [ErrorMessage] } deriving (Show, Monoid)
174 { runMultipleErrors :: [ErrorMessage] } deriving (Show, Monoid)
176+instance UnificationError Type MultipleErrors where
177+ occursCheckFailed = errorMessage . occursCheckFailed
179+instance UnificationError Kind MultipleErrors where
180+ occursCheckFailed = errorMessage . occursCheckFailed
130-- Simplify an error message
183-- Simplify an error message
@@ -134,6 +187,10 @@ simplifyErrorMessage = unwrap Nothing
135 unwrap :: Maybe SourceSpan -> ErrorMessage -> ErrorMessage
188 unwrap :: Maybe SourceSpan -> ErrorMessage -> ErrorMessage
136 unwrap pos (ErrorInExpression _ err) = unwrap pos err
189 unwrap pos (ErrorInExpression _ err) = unwrap pos err
190+ unwrap pos (ErrorInInstance name ts err) = ErrorInInstance name ts (unwrap pos err)
191+ unwrap pos (ErrorInSubsumption t1 t2 err) = ErrorInSubsumption t1 t2 (unwrap pos err)
192+ unwrap pos (ErrorUnifyingTypes _ _ err) = unwrap pos err
193+ unwrap pos (ErrorCheckingKind ty err) = ErrorCheckingKind ty (unwrap pos err)
137 unwrap pos (ErrorInModule mn err) = ErrorInModule mn (unwrap pos err)
194 unwrap pos (ErrorInModule mn err) = ErrorInModule mn (unwrap pos err)
138 unwrap pos (NotYetDefined ns err) = NotYetDefined ns (unwrap pos err)
195 unwrap pos (NotYetDefined ns err) = NotYetDefined ns (unwrap pos err)
139 unwrap _ (PositionedError pos err) = unwrap (Just pos) err
196 unwrap _ (PositionedError pos err) = unwrap (Just pos) err