c2hs
c2hs copied to clipboard
Redundant import when creating foreign #pointer
e.g.
module Test where
data Test
{#pointer *test as TestPtr foreign -> Test}
generates
module Test where
import qualified Foreign.ForeignPtr as C2HSImp
import qualified Foreign.Ptr as C2HSImp
data Test
type TestPtr = C2HSImp.ForeignPtr (Test)
The extra (unused) Foreign.Ptr
import blows up on -Werror
.
I've run into something very similar to fix alongside the above, when the (admittedly low priority) bug does get addressed: those same two imports are added even if the macro includes nocode
. The type safety (-> Test
) doesn't affect things.
Basically, it seems like every #pointer
macro imports Foreign.Ptr
and every #pointer ... foreign
also imports Foreign.ForeignPtr
. In certain cases, those are not necessary:
-
#pointer ... nocode
never needs any imports; the user will probably need them in defining the type, but even if that does occur in the same module, they'll probably be using their own qualified name. -
#pointer ... foreign
needsForeign.Ptr
only ifnewtype
is also specified; otherwise C2HS doesn't create thewith*
marshalling function that uses it.
I suppose it's possible that the registration requires those types to be present, but not knowing the backend code, I'd guess it's probably fine leaving (or moving) the importing of those modules to #fun
or other macros, which would probably be needing them for other reasons anyway.