Skip to content

ffi.Pointer.fromFunction error Exceptional return value must be a constant #1724

@Ben1980

Description

@Ben1980

With the following code

iostream.value.ref.vtable.ref.set_timeout = ffi.Pointer.fromFunction(
      _setTimeout,
      dc_status_t.DC_STATUS_TIMEOUT
    );

OR

iostream.value.ref.vtable.ref.set_timeout = ffi.Pointer.fromFunction(
      _setTimeout,
      -7,
);

I get the error

Error (Xcode): ../lib/flutter_dive_computer.dart:273:61: Error: Exceptional return value must be a constant.

It will only compile for 7, but not -7. The respective enum I need to use here is coming from ffigen

enum dc_status_t {
  DC_STATUS_SUCCESS(0),
  DC_STATUS_DONE(1),
  DC_STATUS_UNSUPPORTED(-1),
  DC_STATUS_INVALIDARGS(-2),
  DC_STATUS_NOMEMORY(-3),
  DC_STATUS_NODEVICE(-4),
  DC_STATUS_NOACCESS(-5),
  DC_STATUS_IO(-6),
  DC_STATUS_TIMEOUT(-7),
  DC_STATUS_PROTOCOL(-8),
  DC_STATUS_DATAFORMAT(-9),
  DC_STATUS_CANCELLED(-10);

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

  static dc_status_t fromValue(int value) => switch (value) {
        0 => DC_STATUS_SUCCESS,
        1 => DC_STATUS_DONE,
        -1 => DC_STATUS_UNSUPPORTED,
        -2 => DC_STATUS_INVALIDARGS,
        -3 => DC_STATUS_NOMEMORY,
        -4 => DC_STATUS_NODEVICE,
        -5 => DC_STATUS_NOACCESS,
        -6 => DC_STATUS_IO,
        -7 => DC_STATUS_TIMEOUT,
        -8 => DC_STATUS_PROTOCOL,
        -9 => DC_STATUS_DATAFORMAT,
        -10 => DC_STATUS_CANCELLED,
        _ => throw ArgumentError("Unknown value for dc_status_t: $value"),
      };
}

How can I fix this? Or is it a bug?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions