ochafik/nativelibs4java — Issue #256: [JNAerator] getEnumField returns incompatible type
Author: finson
Created: 2012-02-07 05:12:25+00:00
State: open

The code generated for accessing a struct with enums doesn't compile. For example, given this C code:

```
typedef enum cec_logical_address
{
CECDEVICE_UNKNOWN = -1,
CECDEVICE_TV = 0,
[---snip---]
} cec_logical_address;

typedef struct cec_command
{
cec_logical_address initiator;
cec_logical_address destination;
[---snip---]
```

JNAerator produces the following Java code, which does not compile.

```
public class cec_command extends StructObject {
...
/// C type : cec_logical_address
@Field(0)
public IntValuedEnum initiator() {
return this.io.getEnumField(this, 0);
}
```

The compiler error is:
```
Type mismatch: cannot convert from ValuedEnum>> to IntValuedEnum
```

I can get it to compile by modifying the generated code like this, although this may not be the best solution.

```
public IntValuedEnum initiator() {
ValuedEnum r = this.io.getEnumField(this, 0);
return (IntValuedEnum)r;
}
```

I believe that this situation is a result of commit 756e7e64ee91b825fbae3769012e33867822f831 which was part of the fix for issue #231.

Any thoughts on the best way to fix this? Thanks. Doug