Skip to content

πŸ› ffigen: Struct member function pointer does **not** rename reserved keyword parameters (top-level functions correctly do)Β #2795

@dzylikecode

Description

@dzylikecode

Version
ffigen: 20.0.0
Dart: 3.10.0
Platform: Linux


Summary

When generating bindings, top-level C functions have their parameter names sanitized correctly (e.g., in β†’ in$), but struct field function pointers do not.

This inconsistency results in invalid Dart code when the C parameter name is a Dart reserved keyword.

This issue is related to #512, but this time the bug is specifically inside struct member function pointers rather than top-level functions.


πŸ”„ Minimal reproducible example

C header (test.h)

void var(void *in);

struct cls {
    void (*var)(void *in);
};

πŸ“„ Generated Dart code

βœ… Top-level function (correct)

@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(symbol: 'var')
external void var$(ffi.Pointer<ffi.Void> in$);

Notice in was correctly renamed to in$.


❌ Struct field function pointer (incorrect)

final class cls extends ffi.Struct {
  external ffi.Pointer<
      ffi.NativeFunction<
          ffi.Void Function(ffi.Pointer<ffi.Void> in)>> var$1;
}

This still contains:

... Function(ffi.Pointer<ffi.Void> in)

where in is a Dart reserved keyword β†’ Dart compilation fails.


❗ Problem

ffigen already has logic to rename reserved keywords for parameters in top-level functions, but this renaming is not applied to:

  • function pointer parameters inside struct fields
  • function pointer typedefs
  • callbacks

This inconsistency causes generated code to be syntactically invalid.


βœ… Expected behavior

ffigen should apply the same identifier sanitization logic everywhere, including:

  • top-level functions
  • nested typedefs
  • struct field function pointers
  • callback signatures

Example of expected output:

ffi.Void Function(ffi.Pointer<ffi.Void> in$)

or:

ffi.Void Function(ffi.Pointer<ffi.Void> arg0)

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions