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

Do not crash with 'c2hs: No match in record selector posRow' #183

Closed hth313 closed 7 years ago

hth313 commented 7 years ago

I had this crash when trying to generate Haskell code for a simple enum.

The posRow selector only works on Position data, and apparently I got something else. As it had a Maybe wrapped around it, I simply allow it to become Nothing to avoid the crash. I am not sure how it blends with the code there, but the generated output looks fine.

Håkan

kolmodin commented 7 years ago

Can you share what the enum looked like?

hth313 commented 7 years ago

I cut down the code a bit, here is the header file:

enum Tags { x };

And here is the .chs file:

#include "foo.h"

{#enum Tags {} #}

The problem disappears if I add a module line in the .chs file.

kolmodin commented 7 years ago

LGTM. In your example, c2hs has no issue with generating a constructor x which obviously won't compile. To get valid haskell, this could be used;

{#enum Tags {upcaseFirstLetter} #}