From: simonpj@microsoft.com Date: Tue, 5 Jan 2010 09:55:32 +0000 (+0000) Subject: Improve error message (idea in Trac #3805) X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=23cb13ad4de8021cfba9644cf1e993df99a4f4c1 Improve error message (idea in Trac #3805) If we see foreign export ccall foo :: ...blah... we now use the "foreign" to suggest -XForeignFunctionInterface --- diff --git a/compiler/parser/RdrHsSyn.lhs b/compiler/parser/RdrHsSyn.lhs index 746f3d6..300d886 100644 --- a/compiler/parser/RdrHsSyn.lhs +++ b/compiler/parser/RdrHsSyn.lhs @@ -867,8 +867,20 @@ checkValSig checkValSig (L l (HsVar v)) ty | isUnqual v && not (isDataOcc (rdrNameOcc v)) = return (TypeSig (L l v) ty) -checkValSig (L l _) _ +checkValSig lhs@(L l _) _ + | looks_like_foreign lhs + = parseError l "Invalid type signature; perhaps you meant to use -XForeignFunctionInterface?" + | otherwise = parseError l "Invalid type signature" + where + -- A common error is to forget the ForeignFunctionInterface flag + -- so check for that, and suggest. cf Trac #3805 + -- Sadly 'foreign import' still barfs 'parse error' because 'import' is a keyword + looks_like_foreign (L _ (HsVar v)) = v == foreign_RDR + looks_like_foreign (L _ (HsApp lhs _)) = looks_like_foreign lhs + looks_like_foreign _ = False + + foreign_RDR = mkUnqual varName (fsLit "foreign") \end{code}