This repository was archived by the owner on Nov 10, 2026. It is now read-only.
Repository navigation
Bridge closures with closure parameters in the remaining directions - #305
Merged
Merged
Conversation
#249 handled a Kotlin closure with closure parameters that is called from Swift through the @_cdecl path. Three cases still sent the nested closure arguments through AnyBridging, which cannot convert between Swift closures and Kotlin functions: - a Swift closure exposed to Kotlin (convertToCDecl) and called from Kotlin with a Kotlin lambda - a Swift closure assigned to a Kotlin-native property (convertToJava) and called from Kotlin with a Kotlin lambda - a Kotlin-native closure (convertClosureFromJava) called from Swift with a Swift closure Swift closures are now wrapped so that their function-typed parameters arrive as Java objects and are converted using their static types. The wrapper captures the closure value when it is bridged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
marcprux
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#249 made it possible for Swift to call a Kotlin closure that takes closure parameters, through the
@_cdeclpath (skiptools/skip-bridge#109). Three other cases still sent the nested closure arguments throughAnyBridging, which cannot convert between Swift closures and Kotlin functions:convertToCDeclUnable to bridge Kotlin/Java instanceconvertToJavaconvertClosureFromJavaUnable to bridge Swift instance (Function)For example, Kotlin calling
public var onDeposit: @MainActor (@escaping @MainActor () -> Void) -> Voidon a bridged Swift class crashed. This is the reverse of skiptools/skip-bridge#101.Change
convertClosureToJavawraps a Swift closure whose parameters include closures. Those parameters arrive asJavaObjectPointer?and are converted withconvertClosureFromCDeclusing their static types. It is used by bothconvertToCDeclandconvertToJava:.map.throwsand@MainActorare preserved.convertClosureFromJavaconverts closure arguments withconvertClosureToJavabefore callingJavaBackedClosure.invoke.@_cdeclconversion has moved intoconvertClosureFromCDecl, and it now also usesconvertClosureToJavafor its nested arguments, so deeper nesting goes through the same code. The two existing nested-closure tests therefore now expect!after the innerjavaObject(...)call; it cannot fail for a non-optional closure.As with #249,
asyncclosures and closures with more than 5 parameters are still not handled.Testing
BridgeToKotlinTests.testNestedClosureVar,testOptionalNestedClosureVarandBridgeToSwiftTests.testNestedClosureVar. All 253BridgeTo*tests pass.Unable to bridge Kotlin/Java instance.🤖 Generated with Claude Code