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

Mikhail Sosonkin mike at nanotick.net
Sun Aug 4 23:39:39 BST 2013


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)


And the work around:

parseFile :: FilePath -> IO (Either ParseError CTranslUnit)
parseFile path =
    do
     cfile <- Data.ByteString.readFile path
     return (parseC cfile (initpos path))


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.

    header = trace ("err: " ++ show pos) $ (posFile pos) ++ ":" ++
show (posRow pos) ++ ": " ++
             "(column " ++ show (posColumn pos) ++ ") " ++
             "[" ++ show level ++ "]"
    showMsgLines []     = internalErr "No short message or error
message provided."
    showMsgLines (x:xs) = indent ++ ">>> " ++ x ++ "\n" ++ unlines
(map (indent++) xs)


This is triggered when passing in a not preprocessed C file.


Please let me know if this not enough information to reproduce the problem.

Thanks,
Mike.



More information about the Language-c mailing list