[GHC] #14125: Bogus unacceptable type in foreign declaration.

GHC ghc-devs at haskell.org
Thu Aug 17 03:54:13 UTC 2017


#14125: Bogus unacceptable type in foreign declaration.
-------------------------------------+-------------------------------------
        Reporter:  winter            |                Owner:  (none)
            Type:  bug               |               Status:  patch
        Priority:  high              |            Milestone:  8.2.2
       Component:  Compiler (FFI)    |              Version:  8.2.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  GHC rejects       |  Unknown/Multiple
  valid program                      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D3865
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by winter):

 Well, the second case is very easy to create, just use newtype instance:

 {{{
 {-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE FlexibleContexts #-}
 {-# LANGUAGE ForeignFunctionInterface #-}

 module Bug where

 import Foreign
 import Foreign.C.Types
 import System.Posix.Types

 class IOReturn (r :: * -> *) where
     -- | The errno type associated with 'r'
     data IOErrno r :: *

 newtype UnixReturn a = UnixReturn a

 instance IOReturn UnixReturn where
     newtype IOErrno UnixReturn = UnixErrno CInt

 foreign import ccall unsafe "HsBase.h __hscore_get_errno" get_errno :: IO
 (IOErrno UnixReturn)
 }}}

 {{{
 [1 of 1] Compiling Bug              ( Main.hs, Main.o )

 Main.hs:20:1: error:
     • Unacceptable result type in foreign declaration:
         ‘IOErrno UnixReturn’ cannot be marshalled in a foreign call
     • When checking declaration:
         foreign import ccall unsafe "HsBase.h __hscore_get_errno"
 get_errno
           :: IO (IOErrno UnixReturn)
    |
 20 | foreign import ccall unsafe "HsBase.h __hscore_get_errno" get_errno
 :: IO (IOErrno UnixReturn)
    |
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14125#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list