Skip to content

[swift2objc] Support generics referred types#3255

Open
AmrAhmed119 wants to merge 6 commits intodart-lang:mainfrom
AmrAhmed119:generic_referred_types
Open

[swift2objc] Support generics referred types#3255
AmrAhmed119 wants to merge 6 commits intodart-lang:mainfrom
AmrAhmed119:generic_referred_types

Conversation

@AmrAhmed119
Copy link
Contributor

Description

Previously, generic type arguments were not parsed from the symbolgraph tokens, This PR adds support for parsing and preserving generic referred types (e.g. Array<T>, Dictionary<K, V>, Set<T>) in the generated wrappers.

Supports Single generic parameters (Array<T>), Multiple parameters (Dictionary<K, V>), Nested generics (Array<Dictionary<Int, Set<String>>>).

It’s been about a year since I last contributed to the package, so I may have missed some context or cases. 🙃

Related Issues

Fixes #2485

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.

@AmrAhmed119
Copy link
Contributor Author

Ready for review @liamappelbe (cause I can't request review).

@liamappelbe liamappelbe self-requested a review March 23, 2026 01:29
@github-actions
Copy link

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-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.

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.

Copy link
Contributor

@liamappelbe liamappelbe left a comment

Choose a reason for hiding this comment

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

Nice! Looks pretty good already.

@visibleForTesting
static Iterable<Json> splitToken(Json token) sync* {
const splittables = ['(', ')', '?', ',', '->'];
const splittables = ['(', ')', '?', ',', '->', '>'];
Copy link
Contributor

Choose a reason for hiding this comment

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

I went down a bit of a rabbit hole on this. Swift has variadic generics, like C++. It's possible to write a variadic generic class, and then instantiate it with no type params. That means that < should probably be added to the splittables.

struct TupleContainer<each T> {
    let items: (repeat each T)
}

let empty = TupleContainer<>() 

If possible, can you add a test for this case? Since we don't support generic classes yet, you'd need to find a variadic generic in the core libraries, so it's ok if this isn't testable yet (in that case just test it in token_list_test.dart)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The closest thing I found in Foundation is Predicate, but it doesn’t work directly as it’s not bridged and is initialized with a closure. However, I can confirm that the symbol graph does contain a "<>" fragment, so you’re right we do need a split here.

image

For now, I’ve added a test in token_list_test.dart to cover this case.

@AmrAhmed119 AmrAhmed119 requested a review from liamappelbe March 23, 2026 04:39
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.

[swift2objc] Support generics referred types

2 participants