Repository navigation
JNI: fix async thunks for results returned through out parameters - #925
Merged
Merged
Conversation
Async functions returning a generic type, an existential or a tuple write their result into out parameters and give Java a future of Void. The completion call rendered the empty result conversion instead, which produced `[jvalue(l: )]` and failed to compile. Complete the future with nil in that case. Fixes swiftlang#752
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #752
When an async function returns its result through out parameters, the JNI thunk completes the future with
[jvalue(l: )], which doesn't compile. The issue shows it for a generic result likeMyID<String>, butany Pand tuple results hit the same line, since all three write the value into out parameters and give Java aCompletableFuture<Void>. The result conversion renders nothing there, so there's no value to pass.This completes the future with
nilwhen the native result type is void, like theVoidpath already does. The Java side reads the value from the out parameters inthenApply, so the future only has to signal that it's done.I added a parameterized test in JNIAsyncTests for the generic, existential and tuple cases. It fails without the source change, and the rest of JExtractSwiftTests still passes.
I also typechecked the generated thunks with swiftc for those three plus a class method:
cannot find 'jvalue(l:)' in scopebefore, clean after in Swift 5 mode (what the samples use). In Swift 6 mode the existential one still fails onUnsafeMutablePointer<type(of: value)>, but a plain syncany Preturn does too, so that's a separate bug.