-
Notifications
You must be signed in to change notification settings - Fork 122
JNI: fix non-compiling async thunks for protocol boxes and generic types #905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2026 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import JExtractSwiftLib | ||
| import SwiftJavaConfigurationShared | ||
| import Testing | ||
|
|
||
| @Suite | ||
| struct JNIAsyncSelfCaptureTests { | ||
|
|
||
| @Test("Import: class async method captures converted self pointer (Swift)") | ||
| func classAsyncMethod_swift() throws { | ||
| try assertOutput( | ||
| input: """ | ||
| public class MyClass { | ||
| public func compute() async -> Int64 { 42 } | ||
| } | ||
| """, | ||
| .jni, | ||
| .swift, | ||
| detectChunkByInitialLines: 1, | ||
| expectedChunks: [ | ||
| """ | ||
| @_cdecl("Java_com_example_swift_MyClass__00024compute__JLjava_util_concurrent_CompletableFuture_2") | ||
| ... | ||
| nonisolated(unsafe) let selfPointerSendable$ = selfPointer$ | ||
| ... | ||
| task = Task.immediate { | ||
| ... | ||
| let selfPointer$ = selfPointerSendable$ | ||
| ... | ||
| let swiftResult$ = await selfPointer$.pointee.compute() | ||
| """ | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| @Test("Import: protocol box async method captures loaded existential (Swift)") | ||
| func protocolBoxAsyncMethod_swift() throws { | ||
| try assertOutput( | ||
| input: """ | ||
| public protocol Worker { | ||
| func work() async -> Int64 | ||
| } | ||
| """, | ||
| .jni, | ||
| .swift, | ||
| detectChunkByInitialLines: 1, | ||
| expectedChunks: [ | ||
| """ | ||
| @_cdecl("Java_com_example_swift_WorkerBox__00024work__JJLjava_util_concurrent_CompletableFuture_2") | ||
| ... | ||
| nonisolated(unsafe) let selfPointerExistentialSendable$ = selfPointerExistential$ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh, re-reading these now I guess we should be naming them |
||
| ... | ||
| task = Task.immediate { | ||
| ... | ||
| let selfPointerExistential$ = selfPointerExistentialSendable$ | ||
| ... | ||
| let swiftResult$ = await selfPointerExistential$.work() | ||
| """ | ||
| ], | ||
| notExpectedChunks: [ | ||
| "nonisolated(unsafe) let selfPointerSendable$", | ||
| "nonisolated(unsafe) let selfTypePointerSendable$", | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| @Test("Import: generic class async method captures only self pointer (Swift)") | ||
| func genericClassAsyncMethod_swift() throws { | ||
| try assertOutput( | ||
| input: """ | ||
| public class Box<T> { | ||
| public func compute() async -> Int64 { 42 } | ||
| } | ||
| """, | ||
| .jni, | ||
| .swift, | ||
| detectChunkByInitialLines: 1, | ||
| expectedChunks: [ | ||
| """ | ||
| extension Box: _SwiftModule_Box_opener { | ||
| ... | ||
| nonisolated(unsafe) let selfPointerSendable$ = selfPointer$ | ||
| ... | ||
| task = Task.immediate { | ||
| ... | ||
| let selfPointer$ = selfPointerSendable$ | ||
| ... | ||
| let swiftResult$ = await selfPointer$.pointee.compute() | ||
| """ | ||
| ], | ||
| notExpectedChunks: [ | ||
| "selfTypePointerSendable$", | ||
| ] | ||
| ) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.