Skip to content

JNI: fix async thunks for results returned through out parameters - #925

Merged
ktoso merged 1 commit into
swiftlang:mainfrom
Om-singhaI:fix-752-async-out-param-result
Oct 2, 2026
Merged

ktoso merged 1 commit into
swiftlang:mainfrom
Om-singhaI:fix-752-async-out-param-result

Conversation

@Om-singhaI

Copy link
Copy Markdown
Contributor

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 like MyID<String>, but any P and tuple results hit the same line, since all three write the value into out parameters and give Java a CompletableFuture<Void>. The result conversion renders nothing there, so there's no value to pass.

This completes the future with nil when the native result type is void, like the Void path already does. The Java side reads the value from the out parameters in thenApply, 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 scope before, clean after in Swift 5 mode (what the samples use). In Swift 6 mode the existential one still fails on UnsafeMutablePointer<type(of: value)>, but a plain sync any P return does too, so that's a separate bug.

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
@Om-singhaI
Om-singhaI requested a review from ktoso as a code owner September 30, 2026 22:27

@ktoso ktoso left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good thank you!

@ktoso
ktoso merged commit 9cacf22 into swiftlang:main Oct 2, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JNI async thunk generates empty jvalue(l: ) for generic result

2 participants