[swift2objc] Support generics referred types#3255
[swift2objc] Support generics referred types#3255AmrAhmed119 wants to merge 6 commits intodart-lang:mainfrom
Conversation
|
Ready for review @liamappelbe (cause I can't request review). |
PR HealthBreaking changes ✔️
This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with 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.
This check can be disabled by tagging the PR with |
liamappelbe
left a comment
There was a problem hiding this comment.
Nice! Looks pretty good already.
| @visibleForTesting | ||
| static Iterable<Json> splitToken(Json token) sync* { | ||
| const splittables = ['(', ')', '?', ',', '->']; | ||
| const splittables = ['(', ')', '?', ',', '->', '>']; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
For now, I’ve added a test in token_list_test.dart to cover this case.
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
dart tool/ci.dart --alllocally 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 toplevelpubspec.yamlworkspace.CHANGELOG.mdfor the relevant packages. (Not needed for small changes such as doc typos).