[Vala] Name clashes in generated C code



Hi,

I have a simple Vala program

public struct Struct { string name; }
public enum Type { STRUCT }


It looks fine, but if you try to compile it fails with following error:


--------------------------------
$ CC=clang valac a.vala
/usr/local/google/home/anatol/sources/learning/vala/a.vala.c:22:2:
error: expected '}'
        TYPE_STRUCT
        ^
/usr/local/google/home/anatol/sources/learning/vala/a.vala.c:11:21:
note: instantiated from:
#define TYPE_STRUCT (struct_get_type ())
                    ^
/usr/local/google/home/anatol/sources/learning/vala/a.vala.c:21:15:
note: to match this '{'
typedef enum  {
              ^
/usr/local/google/home/anatol/sources/learning/vala/a.vala.c:75:38:
error: initializer element is not a compile-time
      constant
                static const GEnumValue values[] = {{TYPE_STRUCT,
"TYPE_STRUCT", "struct"}, {0, NULL, NULL}};

^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 diagnostics generated.
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
----------------------------------


The problem here a name clash in generated Vala code - TYPE_STRUCT
both generated as type of Struct

#define TYPE_STRUCT (struct_get_type ())

and as a enum value

typedef enum  {
    TYPE_STRUCT
} Type;


what is the best way to avoid such clashes? Is it possible to change
enum names to something else. I can change enum name from Type to
something else e.g. RecordType, but I would like to know if there is a
better solution.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]