Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swift2objc] Parsing is flaky #1670

Open
liamappelbe opened this issue Oct 22, 2024 · 1 comment
Open

[swift2objc] Parsing is flaky #1670

liamappelbe opened this issue Oct 22, 2024 · 1 comment
Assignees
Milestone

Comments

@liamappelbe
Copy link
Contributor

I'm running #1367 (with #1668 patched) on the AVFAudio module to try to see if I can migrate the ffigen objc example to swift. That'll be a good milestone to demonstrate binding a simple, but realistic, Apple API.

The most important class for this example is AVAudioPlayer, but currently it's flaky whether that class even exists in the list of declarations returned by parseAst.

@liamappelbe liamappelbe self-assigned this Oct 22, 2024
liamappelbe added a commit to Mohammad3id/native that referenced this issue Oct 22, 2024
@liamappelbe
Copy link
Contributor Author

Fixed in #1668.

The main problem was that we're indicating errors by throwing exceptions. So if, for example, a method returned an enum, which we don't support yet, parseDeclaration would throw. Then since the method parser wasn't catching that exception, it also propagated up through _parseCompoundDeclaration, effectively removing that declaration. The fix is to catch the error in _parseCompoundDeclaration and just omit that method. I added tryParseDeclaration that wraps parseDeclaration, logs the exception and returns null.

More generally, any time we're calling parseDeclaration, if we want to gracefully handle a problem with the declaration, we should instead call tryParseDeclaration and handle the nullable result. I had a quick look at all the call sites and I don't think there are any other cases like this at the moment.

@liamappelbe liamappelbe moved this to In progress in ObjC/Swift interop Oct 23, 2024
@liamappelbe liamappelbe added this to the SwiftGen MVP milestone Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Development

No branches or pull requests

1 participant