crystal-lang/crystal_lib

Weird typedef struct is translated incorrectly

aladagemre opened this issue · 3 comments

When generating binding for igraph see

https://github.com/igraph/igraph/blob/a98fccd3fb2a9f67551a09d4159ef268ee62c658/include/igraph_datatype.h

typedef struct igraph_s {
  igraph_integer_t n;
  igraph_bool_t directed;
  igraph_vector_t from;
  igraph_vector_t to;
  igraph_vector_t oi;
  igraph_vector_t ii;
  igraph_vector_t os;
  igraph_vector_t is;
  void *attr;
} igraph_t;

This code is translated into

struct S
  n : IntegerT
  directed : BoolT
  from : VectorT
  to : VectorT
  oi : VectorT
  ii : VectorT
  os : VectorT
  is : VectorT
  attr : Void*
end
type T = S

And then uses T* whenever functions indeed expect S_. When we replace all T_ with S*, the code works.

I'm not sure what's the issue. Is it that T is used instead of T*? The type declaration seems fine, although maybe in those cases declaring the struct as struct T (without declaring S) should be good?

when I use T.new, it says T doesn't have method new.
When I try to cast T to S, it says S can't be casted to T.

I don't know what's the reason for this.