diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift index 43b168d4..090a83cf 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift @@ -1227,12 +1227,14 @@ extension JNISwift2JavaGenerator { } else { "await" } - printer.print("let swiftResult$ = \(tryAwaitString) \(placeholderWithoutTry)") - printer.print("environment = try! JavaVirtualMachine.shared().environment()") - let inner = nativeFunctionSignature.result.conversion.render(&printer, "swiftResult$") if swiftFunctionResultType.isVoid { + printer.print("\(tryAwaitString) \(placeholderWithoutTry)") + printer.print("environment = try! JavaVirtualMachine.shared().environment()") printer.print("_ = environment.interface.CallBooleanMethodA(environment, globalFuture, \(completeMethodID), [jvalue(l: nil)])") } else { + printer.print("let swiftResult$ = \(tryAwaitString) \(placeholderWithoutTry)") + printer.print("environment = try! JavaVirtualMachine.shared().environment()") + let inner = nativeFunctionSignature.result.conversion.render(&printer, "swiftResult$") let result: String if nativeFunctionSignature.result.javaType.requiresBoxing { printer.print("let boxedResult$ = SwiftJavaRuntimeSupport._JNIBoxedConversions.box(\(inner), in: environment)") diff --git a/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift b/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift index d430276b..317c194d 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIAsyncTests.swift @@ -69,7 +69,7 @@ struct JNIAsyncTests { let deferEnvironment = try! JavaVirtualMachine.shared().environment() deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture) } - let swiftResult$ = await SwiftModule.asyncVoid() + await SwiftModule.asyncVoid() environment = try! JavaVirtualMachine.shared().environment() _ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: nil)]) } @@ -82,7 +82,7 @@ struct JNIAsyncTests { let deferEnvironment = try! JavaVirtualMachine.shared().environment() deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture) } - let swiftResult$ = await SwiftModule.asyncVoid() + await SwiftModule.asyncVoid() environment = try! JavaVirtualMachine.shared().environment() _ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: nil)]) } @@ -144,7 +144,7 @@ struct JNIAsyncTests { deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture) } do { - let swiftResult$ = try await SwiftModule.async() + try await SwiftModule.async() environment = try! JavaVirtualMachine.shared().environment() _ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: nil)]) } @@ -164,7 +164,7 @@ struct JNIAsyncTests { deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture) } do { - let swiftResult$ = try await SwiftModule.async() + try await SwiftModule.async() environment = try! JavaVirtualMachine.shared().environment() _ = environment.interface.CallBooleanMethodA(environment, globalFuture, _JNIMethodIDCache.CompletableFuture.complete, [jvalue(l: nil)]) }