dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
115 stars 40 forks source link

Unsupported generation of C enums #1402

Open hkaripineni opened 1 month ago

hkaripineni commented 1 month ago

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");
    }
  }
dcharkes commented 1 month ago

@hkaripineni What version of Dart are you running on?