Skip to content

[ffigen] Fix category filtering bug - #3557

Open
liamappelbe wants to merge 58 commits into
mainfrom
ffigen_category_filter_bug
Open

[ffigen] Fix category filtering bug#3557
liamappelbe wants to merge 58 commits into
mainfrom
ffigen_category_filter_bug

Conversation

@liamappelbe

@liamappelbe liamappelbe commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

ObjC categories map pretty neatly to Dart extension methods. The only issue we run into is methods returning instancetype, which are special cased in ObjC to return an instance of the receiver type (ie, if Child overrides a method on Base that returns instancetype, the method on Base returns Base while the method on Child returns Child), and can't be cleanly represented in Dart's inheritance semantics. So whenever we see a method returning instancetype, we have to copy it to all the subtypes, and from a category to its parent interface.

Before this PR there was a bug where that copying logic could bypass the usual filters. If a category was filtered out, we would still copy its instancetype methods to the parent interface. I had ignored it as an edge case, but I bumped into it again during the isIncluded PR, and it turns out to be fairly easy to fix now.

Basically, we just track a method's originCategory, then in apply_config_filterse if the origin category is filtered then we filter out the method.

To avoid making breaking changes to package:objective_c, I then had to add explicit include rules for all the categories that added instancetype methods to an interface.

Fixes #3546

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
objective_c Breaking 9.5.0 9.6.0-wip 9.6.0-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

@liamappelbe
liamappelbe marked this pull request as ready for review August 17, 2026 06:45
@liamappelbe liamappelbe changed the title WIP [ffigen] Fix category filtering bug [ffigen] Fix category filtering bug Aug 17, 2026

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// included by the config filters, since this method copying visit happens
// before the filtering visit. This is technically a bug, but it's unlikely
// to bother anyone, and the fix would be complicated. So we'll ignore it
// for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 Great that we can fix this now!

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] Bug in ObjC category filtering

2 participants