Ticket #7243 (new bug)

Opened 8 months ago

Last modified 8 months ago

regression: acceptable foreign result types

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

Description

The following short file is rejected:

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

The error is:

test.hs:2:1:
    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

Changed 8 months ago by td123

  • cc gostrc@… added

Changed 8 months ago by romildo

  • cc malaquias@… added

Changed 8 months ago by igloo

  • owner set to igloo
  • difficulty set to Unknown
  • component changed from Compiler to Compiler (FFI)
  • milestone set to 7.6.2

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.

Changed 8 months ago by simonpj

See also #5610.

Note: See TracTickets for help on using tickets.