From d79dbc5f81a83414a7e814fcc23e601d4fee8891 Mon Sep 17 00:00:00 2001 From: Aman Date: Sat, 20 Dec 2025 23:32:20 +0530 Subject: [PATCH] Fixs warning of try await --- .../JNI/JNISwift2JavaGenerator+NativeTranslation.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift index d8b0a1d1b..914e09cd4 100644 --- a/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift +++ b/Sources/JExtractSwiftLib/JNI/JNISwift2JavaGenerator+NativeTranslation.swift @@ -1033,7 +1033,15 @@ extension JNISwift2JavaGenerator { ) func printDo(printer: inout CodePrinter) { - printer.print("let swiftResult$ = await \(placeholder)") + // Generate proper 'try await' order: if placeholder already has 'try', remove it and add 'try await', otherwise just add 'try await' + let modifiersAndPlaceholder: String + if placeholder.hasPrefix("try ") { + let placeholderWithoutTry = placeholder.replacingOccurrences(of: "^try ", with: "", options: .regularExpression) + modifiersAndPlaceholder = "try await \(placeholderWithoutTry)" + } else { + modifiersAndPlaceholder = "try await \(placeholder)" + } + printer.print("let swiftResult$ = \(modifiersAndPlaceholder)") printer.print("environment = try! JavaVirtualMachine.shared().environment()") let inner = nativeFunctionSignature.result.conversion.render(&printer, "swiftResult$") if swiftFunctionResultType.isVoid {