@@ -51,7 +51,9 @@ import qualified Text.Parsec as P
52data SimpleErrorMessage
52data SimpleErrorMessage
53 = ErrorParsingExterns P.ParseError
53 = ErrorParsingExterns P.ParseError
54+ | ErrorParsingFFIModule FilePath
54 | ErrorParsingPrelude P.ParseError
55 | ErrorParsingPrelude P.ParseError
56+ | ErrorParsingModule P.ParseError
55 | InvalidExternsFile FilePath
57 | InvalidExternsFile FilePath
56 | CannotGetFileInfo FilePath
58 | CannotGetFileInfo FilePath
57 | CannotReadFile FilePath
59 | CannotReadFile FilePath
@@ -121,7 +123,7 @@ data SimpleErrorMessage
122-- Wrapper of simpler errors
124-- Wrapper of simpler errors
124−data ErrorMessage
126+data ErrorMessage
125 = NotYetDefined [Ident] ErrorMessage
127 = NotYetDefined [Ident] ErrorMessage
126 | ErrorUnifyingTypes Type Type ErrorMessage
128 | ErrorUnifyingTypes Type Type ErrorMessage
127 | ErrorInExpression Expr ErrorMessage
129 | ErrorInExpression Expr ErrorMessage
@@ -142,10 +144,10 @@ data ErrorMessage
142 | PositionedError SourceSpan ErrorMessage
144 | PositionedError SourceSpan ErrorMessage
143 | SimpleErrorWrapper SimpleErrorMessage
145 | SimpleErrorWrapper SimpleErrorMessage
144 deriving (Show)
146 deriving (Show)
146instance UnificationError Type ErrorMessage where
148instance UnificationError Type ErrorMessage where
147 occursCheckFailed t = SimpleErrorWrapper $ InfiniteType t
149 occursCheckFailed t = SimpleErrorWrapper $ InfiniteType t
149instance UnificationError Kind ErrorMessage where
151instance UnificationError Kind ErrorMessage where
150 occursCheckFailed k = SimpleErrorWrapper $ InfiniteKind k
152 occursCheckFailed k = SimpleErrorWrapper $ InfiniteKind k
@@ -155,7 +157,9 @@ instance UnificationError Kind ErrorMessage where
155errorCode :: ErrorMessage -> String
157errorCode :: ErrorMessage -> String
156errorCode em = case unwrapErrorMessage em of
158errorCode em = case unwrapErrorMessage em of
157 (ErrorParsingExterns _) -> "ErrorParsingExterns"
159 (ErrorParsingExterns _) -> "ErrorParsingExterns"
160+ (ErrorParsingFFIModule _) -> "ErrorParsingFFIModule"
158 (ErrorParsingPrelude _) -> "ErrorParsingPrelude"
161 (ErrorParsingPrelude _) -> "ErrorParsingPrelude"
162+ (ErrorParsingModule _) -> "ErrorParsingModule"
159 (InvalidExternsFile _) -> "InvalidExternsFile"
163 (InvalidExternsFile _) -> "InvalidExternsFile"
160 (CannotGetFileInfo _) -> "CannotGetFileInfo"
164 (CannotGetFileInfo _) -> "CannotGetFileInfo"
161 (CannotReadFile _) -> "CannotReadFile"
165 (CannotReadFile _) -> "CannotReadFile"
@@ -224,12 +228,12 @@ errorCode em = case unwrapErrorMessage em of
225-- A stack trace for an error
229-- A stack trace for an error
227−newtype MultipleErrors = MultipleErrors
231+newtype MultipleErrors = MultipleErrors
228 { runMultipleErrors :: [ErrorMessage] } deriving (Show, Monoid)
232 { runMultipleErrors :: [ErrorMessage] } deriving (Show, Monoid)
230instance UnificationError Type MultipleErrors where
234instance UnificationError Type MultipleErrors where
231 occursCheckFailed = occursCheckFailed
235 occursCheckFailed = occursCheckFailed
233instance UnificationError Kind MultipleErrors where
237instance UnificationError Kind MultipleErrors where
234 occursCheckFailed = occursCheckFailed
238 occursCheckFailed = occursCheckFailed
@@ -288,7 +292,7 @@ unwrapErrorMessage em = case em of
288 (SimpleErrorWrapper sem) -> sem
292 (SimpleErrorWrapper sem) -> sem
290replaceUnknowns :: Type -> State UnknownMap Type
294replaceUnknowns :: Type -> State UnknownMap Type
291−replaceUnknowns = everywhereOnTypesM replaceTypes
295+replaceUnknowns = everywhereOnTypesM replaceTypes
293 lookupTable :: (LabelType, Unknown) -> UnknownMap -> (Unknown, UnknownMap)
297 lookupTable :: (LabelType, Unknown) -> UnknownMap -> (Unknown, UnknownMap)
294 lookupTable x m = case M.lookup x m of
298 lookupTable x m = case M.lookup x m of
@@ -348,7 +352,7 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
349 wikiUri :: String
353 wikiUri :: String
350 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
354 wikiUri = "https://github.com/purescript/purescript/wiki/Error-Code-" ++ errorCode e
352 go :: ErrorMessage -> Box.Box
356 go :: ErrorMessage -> Box.Box
353 goSimple (CannotGetFileInfo path) = paras [ line "Unable to read file info: "
357 goSimple (CannotGetFileInfo path) = paras [ line "Unable to read file info: "
354 , indent . line $ path
358 , indent . line $ path
@@ -362,6 +366,9 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
362 goSimple (ErrorParsingExterns err) = paras [ line "Error parsing externs files: "
366 goSimple (ErrorParsingExterns err) = paras [ line "Error parsing externs files: "
363 , indent . line . show $ err
367 , indent . line . show $ err
369+ goSimple (ErrorParsingFFIModule path) = paras [ line "Unable to parse module from FFI file: "
370+ , indent . line $ path
365 goSimple (ErrorParsingPrelude err) = paras [ line "Error parsing prelude: "
372 goSimple (ErrorParsingPrelude err) = paras [ line "Error parsing prelude: "
366 , indent . line . show $ err
373 , indent . line . show $ err
@@ -409,7 +416,7 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
409 goSimple (PartiallyAppliedSynonym name) = line $ "Partially applied type synonym " ++ show name
416 goSimple (PartiallyAppliedSynonym name) = line $ "Partially applied type synonym " ++ show name
410 goSimple (EscapedSkolem binding) = paras $ [ line "Rigid/skolem type variable has escaped." ]
417 goSimple (EscapedSkolem binding) = paras $ [ line "Rigid/skolem type variable has escaped." ]
411 <> foldMap (\expr -> [ line "Relevant expression: "
418 <> foldMap (\expr -> [ line "Relevant expression: "
412− , indent $ line $ prettyPrintValue expr
419+ , indent $ line $ prettyPrintValue expr
413 ]) binding
420 ]) binding
414 goSimple (TypesDoNotUnify t1 t2) = paras [ line "Cannot unify type"
421 goSimple (TypesDoNotUnify t1 t2) = paras [ line "Cannot unify type"
415 , indent $ line $ prettyPrintType t1
422 , indent $ line $ prettyPrintType t1
@@ -432,7 +439,7 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
432 goSimple (NoInstanceFound nm ts) = line $ "No instance found for " ++ show nm ++ " " ++ unwords (map prettyPrintTypeAtom ts)
439 goSimple (NoInstanceFound nm ts) = line $ "No instance found for " ++ show nm ++ " " ++ unwords (map prettyPrintTypeAtom ts)
433 goSimple (DuplicateLabel l expr) = paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
440 goSimple (DuplicateLabel l expr) = paras $ [ line $ "Duplicate label " ++ show l ++ " in row." ]
434 <> foldMap (\expr' -> [ line "Relevant expression: "
441 <> foldMap (\expr' -> [ line "Relevant expression: "
435− , indent $ line $ prettyPrintValue expr'
442+ , indent $ line $ prettyPrintValue expr'
437 goSimple (DuplicateTypeArgument name) = line $ "Duplicate type argument " ++ show name
444 goSimple (DuplicateTypeArgument name) = line $ "Duplicate type argument " ++ show name
438 goSimple (DuplicateValueDeclaration nm) = line $ "Duplicate value declaration for " ++ show nm
445 goSimple (DuplicateValueDeclaration nm) = line $ "Duplicate value declaration for " ++ show nm
@@ -463,7 +470,7 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
463 goSimple (ShadowedName nm) = line $ "Name '" ++ show nm ++ "' was shadowed."
470 goSimple (ShadowedName nm) = line $ "Name '" ++ show nm ++ "' was shadowed."
464 goSimple (WildcardInferredType ty) = line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
471 goSimple (WildcardInferredType ty) = line $ "The wildcard type definition has the inferred type " ++ prettyPrintType ty
465 goSimple PreludeNotPresent = paras [ line $ "There is no Prelude module loaded, and the --no-prelude option was not specified."
472 goSimple PreludeNotPresent = paras [ line $ "There is no Prelude module loaded, and the --no-prelude option was not specified."
466− , line $ "You probably need to install the Prelude and other dependencies using Bower."
473+ , line $ "You probably need to install the Prelude and other dependencies using Bower."
468 go (NotYetDefined names err) = paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map show names) ++ ":"
475 go (NotYetDefined names err) = paras [ line $ "The following are not yet defined here: " ++ intercalate ", " (map show names) ++ ":"
469 , indent $ go err
476 , indent $ go err
@@ -570,10 +577,10 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
570 prettyPrintDictionaryValue (SubclassDictionaryValue sup nm _) = paras [ line $ (show nm) ++ " via superclass"
577 prettyPrintDictionaryValue (SubclassDictionaryValue sup nm _) = paras [ line $ (show nm) ++ " via superclass"
571 , indent $ prettyPrintDictionaryValue sup
578 , indent $ prettyPrintDictionaryValue sup
575 -- Pretty print and export declaration
582 -- Pretty print and export declaration
577 prettyPrintExport :: DeclarationRef -> String
584 prettyPrintExport :: DeclarationRef -> String
578 prettyPrintExport (TypeRef pn _) = show pn
585 prettyPrintExport (TypeRef pn _) = show pn
579 prettyPrintExport (ValueRef ident) = show ident
586 prettyPrintExport (ValueRef ident) = show ident