haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

"Internal type default error" #165

Open Fizzixnerd opened 8 years ago

Fizzixnerd commented 8 years ago

Hello.

I am using c2hs to generate bindings to Wayland. I came across this unhelpful error message. I consider such a thing as a bug; it has halted me from making progress because I don't know what to do.

% c2hs Wayland/Client/Internal/C/Bug.chs
c2hs Wayland/Client/Internal/C/Bug.chs
c2hs: Errors during expansion of binding hooks:

Wayland/Client/Internal/C/Bug.chs:6: (column 3) [ERROR]  >>> Internal type default error!
  Something went wrong.

Here is a minimal example that expresses the bug.

-- Bug.chs
module Main where

#include <inttypes.h>

newtype Bug = Bug { getBug :: {#type uint32_t#} }
{#default in `Bug' [uint32_t] getBug#}

And here is the output of c2hs --version

% c2hs --version
c2hs --version
C->Haskell Compiler, version 0.28.1 Switcheroo, 1 April 2016
  build platform is "x86_64-linux" <1, True, True, 1>

This is the latest version from Cabal.

Finally, I want to express what I was trying to do; I clearly am trying to do something in a strange way, so I might as well tell you what I wanted to have happen.

I have to pass an "opcode" to wayland, represented in the code as a uint32_t. I wanted to newtype over this and create a marshaller as above. I suspect the problem lies in doing weird stuff with newtypes in record syntax with type annotations. If there is a better way, please let me know.

Hope this has been helpful.

Sincerely, Matt