Possible bug in error handling: Language/C/Data/Error.hs

Benedikt Huber benedikt.huber at gmail.com
Mon Aug 12 11:43:11 BST 2013

On 05.08.2013, at 00:39, Mikhail Sosonkin wrote:

> Hello Language-C developers,
> I'll start by saying that I think it's great that you wrote this
> library. While learning how to use it, I believe I found a bug:
> *** Exception: No match in record selector posFile
> it doesn't take much to reproduce:
> parseFile :: FilePath -> IO (Either ParseError CTranslUnit)
> parseFile path =
>    do
>     cfile <- Data.ByteString.readFile path
>     return (parseC cfile nopos)
> The bug is in file Language/C/Data/Error.hs:151:
> showErrorInfo :: String -> ErrorInfo -> String
> showErrorInfo short_msg (ErrorInfo level pos msgs) =
>    header ++ showMsgLines (if null short_msg then msgs else short_msg:msgs)
>    where
> -- at this point 'pos' is nopos which I assume doesn't have posFile defined.
> [..]
> This is triggered when passing in a not preprocessed C file.
Dear Mike,
thanks for the bug report!
You are right, it's a bug to apply posFile without first ensuring isSourcePos.
Although I believe we should have avoided partial functions like posFile in the
first place, I decided to deal with this problem without changing the API. The patch
fixes the problematic code in Error.hs (and a related one in Pretty.hs), and was pushed.

Mon Aug 12 12:10:59 CEST 2013  benedikt.huber at gmail.com                         
  * Fix bug caused by applying posFile to nopos (reported by Mikhail Sosonkin)

cheers, benedikt

More information about the Language-c mailing list