Opened 19 months ago

Last modified 7 months ago

#7243 new bug

regression: acceptable foreign result types

Reported by: dmwit Owned by:
Priority: normal Milestone: 7.6.2
Component: Compiler (FFI) Version: 7.6.1
Keywords: Cc: gostrc@…, malaquias@…, shelarcy@…
Operating System: Unknown/Multiple Architecture: x86_64 (amd64)
Type of failure: GHC rejects valid program Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:


The following short file is rejected:

import Foreign.Ptr
foreign import ccall "wrapper" foo :: IO (FunPtr ())

The error is:

    Unacceptable type in foreign declaration: IO (FunPtr ())
    When checking declaration:
      foreign import ccall safe "wrapper" foo :: IO (FunPtr ())

However, my reading of the 2010 Report suggests this should be acceptable. Specifically:

  • Prelude.IO t is a marshallable foreign result type when t is a marshallable foreign type,
  • all basic foreign types are marshallable foreign types, and
  • FunPtr? a is a basic foreign type for all a.

(Political note: I include this chain of reasoning not because I think others too stupid to recreate it, but because I think it likely that I am not reading the Report correctly, and want to make it easy to detect and correct any misconceptions I have.)

Change History (6)

comment:1 Changed 19 months ago by td123

  • Cc gostrc@… added

comment:2 Changed 19 months ago by romildo

  • Cc malaquias@… added

comment:3 Changed 19 months ago by igloo

  • Component changed from Compiler to Compiler (FFI)
  • Difficulty set to Unknown
  • Milestone set to 7.6.2
  • Owner set to igloo

The problem is:

Dynamic wrapper.
    The type of a wrapper stub has to be of the form ft -> IO (FunPtr ft), where ft may be any foreign type.

e.g. this is accepted:

import Foreign.Ptr
foreign import ccall "wrapper" foo :: () -> IO (FunPtr ())

I'll leave the ticket open, though, as I think we should give the expected pattern in the error message.

comment:4 Changed 19 months ago by simonpj

See also #5610.

comment:5 Changed 9 months ago by igloo

  • Owner igloo deleted

comment:6 Changed 7 months ago by shelarcy

  • Cc shelarcy@… added
Note: See TracTickets for help on using tickets.