Skip to content

[ffigen] Crash when a struct member or typedef is a pointer to a function with an unsupported parameter type #3691

Closed

Description

@jakobkordez

ffigen throws an unhandled exception during code generation when a struct
member or a typedef is a pointer to a function whose parameters include a
type ffigen cannot represent (a C++ reference here). The unsupported type is
detected for functions and for direct function-pointer fields, but not when
the function pointer is reached through a typedef.

Repro

repro.h

struct Widget;
typedef void (*callback)(int, Widget&, int);
struct Holder {
  callback fn;
};

repro.dart

import 'package:ffigen/ffigen.dart';

void main() async {
  await FfiGenerator(
    output: Output(dart: DartOutput(path: Uri.file('repro_bindings.dart'))),
    input: Input(
      entryPoints: [Uri.file('repro.h')],
      compilerOptions: ['-x', 'c++'],
    ),
    visitors: [
      Visitor(struct: (node) => node.isIncluded = true),
    ],
  ).generate();
}

Actual

Unhandled exception:
Unsupported operation: No mapping for type: (Unimplemented: Function parameter has an unsupported type.)
#0      Type.getCType (package:ffigen/src/code_generator/type.dart:52:7)
#1      PointerType.getCType (package:ffigen/src/code_generator/pointer.dart:32:58)
#2      Type.getFfiDartType (package:ffigen/src/code_generator/type.dart:56:45)
#3      Typealias.getFfiDartType (package:ffigen/src/code_generator/typealias.dart:167:17)
#4      Compound.toBindingString (package:ffigen/src/code_generator/compound.dart:200:38)
#5      Writer.generate (package:ffigen/src/code_generator/writer.dart:162:17)

Including the typedef instead of the struct, with
Visitor(typealias: (node) => node.isIncluded = TypealiasInclude.always),
crashes the same way from Typealias.toBindingString.

Activity

  1. added
    lang-cppExperimental C++ support
    and removed
    needs-triageNeeds triage from the team. Remove this label once triaged.
    on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions