native icon indicating copy to clipboard operation
native copied to clipboard

Unsupported generation of C enums

Open hkaripineni opened this issue 1 year ago • 1 comments
trafficstars

Generated bindings for C enum:

enum ENUM_NAME_T {
  VALUE_0(0),
  VALUE_1(1),
  VALUE_2(2),
  VALUE_3(3);

  final int value;
  const ENUM_NAME_T (this.value);

  static ENUM_NAME_T fromValue(int value) => switch (value) {
        0 => VALUE_0,
        1 => VALUE_1,
        2 => VALUE_2,
        3 => VALUE_3,
        _ => throw ArgumentError("Unknown value for ENUM_NAME_T : $value"),
      };
}

The switch expression is giving me these errors:

Expected an identifier, Expected to find ';', Expected a class member

The errors go away when I replace the expression with a statement

static ENUM_NAME_T fromValue(int value) {
    switch (value) {
      case 0:
        return VALUE_0;
      case 1:
        return VALUE_1;
      case 2:
        return VALUE_2;
      case 3:
        return VALUE_3;
      default:
        throw ArgumentError("Unknown value for ENUM_NAME_T: $value");
    }
  }

hkaripineni avatar Aug 08 '24 04:08 hkaripineni

@hkaripineni What version of Dart are you running on?

dcharkes avatar Aug 08 '24 07:08 dcharkes