Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,10 @@ extension JNISwift2JavaGenerator {
printer.print("environment = try! JavaVirtualMachine.shared().environment()")
let inner = nativeFunctionSignature.result.conversion.render(&printer, "swiftResult$")
let result: String
if nativeFunctionSignature.result.javaType.requiresBoxing {
if nativeFunctionSignature.result.javaType.isVoid {
// The result was written to the out parameters, so the Java future is completed with Void
result = "nil"
} else if nativeFunctionSignature.result.javaType.requiresBoxing {
printer.print(
"let boxedResult$ = SwiftJavaRuntimeSupport._JNIBoxedConversions.box(\(inner), in: environment)"
)
Expand Down
47 changes: 47 additions & 0 deletions Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,4 +482,51 @@ struct JNIAsyncTests {
]
)
}

@Test(
"Import: async with result in out parameters completes future with nil (Swift, CompletableFuture)",
arguments: [
(
"""
public struct MyID<T> {
public var rawValue: T
}
public func asyncGeneric() async -> MyID<String>
""",
"asyncGeneric"
),
(
"""
public protocol Shape {
func area() -> Double
}
public func asyncExistential() async -> any Shape
""",
"asyncExistential"
),
(
"public func asyncTuple() async -> (Int64, String)",
"asyncTuple"
),
]
)
func completableFuture_asyncOutParameterResult_swift(input: String, functionName: String) throws {
try assertOutput(
input: input,
.jni,
.swift,
detectChunkByInitialLines: 1,
expectedChunks: [
"""
let swiftResult$ = await SwiftModule.\(functionName)()
environment = try! JavaVirtualMachine.shared().environment()
...
_ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: nil)])
"""
],
notExpectedChunks: [
"[jvalue(l: )]"
]
)
}
}
Loading