id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
3806,Type checking errors in foreign declarations reported at wrong locations,asuffield,,"The following code:
{{{
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign.C.Types

foreign export ccall foo :: CInt -> IO ()
foo ""x"" = return ()
}}}

yields this error:

{{{
TestErr.hs:4:0:
    Couldn't match expected type `CInt' against inferred type `[Char]'
    In the expression: foo
    When checking declaration:
        foreign export ccall ""foo"" foo :: CInt -> IO ()
}}}

The error part is notionally correct, but the location where it is reported is wrong - it's reporting the type declaration as erroneous, while type errors would normally report the function definition.

Compare the error with a non-foreign declaration:

{{{
{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign.C.Types

foo :: CInt -> IO ()
foo ""x"" = return ()
}}}

giving:

{{{
TestErr.hs:5:4:
    Couldn't match expected type `CInt' against inferred type `[Char]'
    In the pattern: ""x""
    In the definition of `foo': foo ""x"" = return ()
}}}

This is the error that I wanted to see.",bug,closed,normal,,Compiler,6.12.1,invalid,,,Unknown/Multiple,Unknown/Multiple,None/Unknown,,,,,
