Skip to content

fix: struct member renamed due to top-level function collision (#2850) - #3725

Open
vikramsingh920 wants to merge 6 commits into
dart-lang:mainfrom
vikramsingh920:fix-ffigen-struct-member-collision-2850
Open

vikramsingh920 wants to merge 6 commits into
dart-lang:mainfrom
vikramsingh920:fix-ffigen-struct-member-collision-2850

Conversation

@vikramsingh920

Copy link
Copy Markdown
Contributor

Description

Fixes an issue in ffigen where struct members were unnecessarily renamed with a $1 suffix when a top-level function or global variable shared the same identifier.

Why:
In Dart, struct field/member identifiers live inside the struct's own class scope and do not collide with top-level functions or variables. Previously, Scope._fillNames() passed all root symbols (namer._used) down to child scopes. As a result, if a top-level C function like FindClass existed, any struct member named FindClass was mistakenly treated as a collision and renamed to FindClass$1.

What changed:

  • In pkgs/ffigen/lib/src/code_generator/scope.dart, child scopes inheriting from root now only receive type-level symbols (classLevelUsed) instead of all root symbols (_used).
  • Added regression test struct_member_toplevel_func_collision_test.dart and its expected golden bindings file.
  • Added entry to pkgs/ffigen/CHANGELOG.md.

Related Issues

Fixes #2850

PR Checklist

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
  • I've run dart tool/ci.dart --all locally and resolved all issues identified. This ensures the PR is formatted, has no lint errors, and ran all code generators. This applies to the packages part of the toplevel pubspec.yaml workspace.
  • All existing and new tests are passing. I added new tests to check the change I am making.
  • The PR is actually solving the issue. PRs that don't solve the issue will be closed. Please be respectful of the maintainers' time. If it's not clear what the issue is, feel free to ask questions on the GitHub issue before submitting a PR.
  • I have updated CHANGELOG.md for the relevant packages. (Not needed for small changes such as doc typos).
  • I have updated the pubspec package version if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ffigen] Struct Member Renamed Due to Top-Level Function Collision

1 participant