Skip to content

Commit 9439bfb

Browse files
authored
[ffigen] Fix function type param name bug (#2797)
1 parent 8f1f806 commit 9439bfb

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

pkgs/ffigen/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
`Declarations.includeMemberSet`, `Declarations.useOriginalName`,
1010
`Declarations.renameWithMap`, `Declarations.useMemberOriginalName`, and
1111
`Declarations.renameMemberWithMap`.
12+
- Fix [a bug](https://github.com/dart-lang/native/issues/2795) where function
13+
pointer param names could collide with keywords.
1214
- Fix [a bug](https://github.com/dart-lang/native/issues/2782) where unnamed
1315
enum constants were being multiply defined.
1416
- Fix [a bug](https://github.com/dart-lang/native/issues/2761) in imported

pkgs/ffigen/lib/src/code_generator/func_type.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ class FunctionType extends Type with HasLocalScope {
3030
String? varArgWrapper,
3131
}) {
3232
final params = varArgWrapper != null ? parameters : dartTypeParameters;
33-
String paramToString(Parameter p) =>
34-
'${typeToString(p.type)} ${writeArgumentNames ? p.originalName : ""}';
33+
String paramToString(Parameter p) {
34+
final name = writeArgumentNames && p.originalName.isNotEmpty
35+
? p.name
36+
: '';
37+
return '${typeToString(p.type)} $name';
38+
}
39+
3540
String? varArgPack;
3641
if (varArgWrapper != null && varArgParameters.isNotEmpty) {
3742
final varArgPackBuf = StringBuffer();

pkgs/ffigen/test/collision_tests/expected_bindings/_expected_reserved_keyword_collision_bindings.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ class NativeLibrary {
3636
set import(int value) => _import.value = value;
3737
}
3838

39+
final class Repro2795 extends ffi.Struct {
40+
external ffi.Pointer<
41+
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void> in$)>
42+
>
43+
var$1;
44+
}
45+
3946
final class abstract$ extends ffi.Opaque {}
4047

4148
enum export$ {

pkgs/ffigen/test/collision_tests/reserved_keyword_collision.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ enum export { covariant };
88
void implements(int dynamic, int in, int deferred) {}
99
int import = 123;
1010
typedef void var;
11+
12+
// Regression test for https://github.com/dart-lang/native/issues/2795
13+
struct Repro2795 {
14+
void (*var)(void* in);
15+
};

0 commit comments

Comments
 (0)