crystal_lib icon indicating copy to clipboard operation
crystal_lib copied to clipboard

Usage of unexposed enums leads to generation of broken bindings

Open olbat opened this issue 4 years ago • 1 comments

Unexposed enums in struct fields lead to generation of bindings with Void as field's type. As struct's fields cannot have the Void type, the generated binding is broken.

To reproduce:

$ cat <<'EOF' > /tmp/bug.h
struct st {
	int a;
	enum { x, y } b;
};
struct st *test();
EOF

$ crystal src/main.cr <<'EOF'
@[Include("/tmp/bug.h", prefix: %w(test))]
lib LibTest
end
EOF

lib LibTest
  fun  = test : St*
  struct St
    a : LibC::Int
    b : Void
  end
end

When trying to use the binding, the following error is thrown at compile time: can't use Void as a struct field type.

olbat avatar Mar 01 '20 17:03 olbat

I've proposed a fix for this in #67.

olbat avatar Mar 01 '20 17:03 olbat