Skip to content

Test closures with closure parameters in every bridging direction - #124

Draft
piercifani wants to merge 1 commit into
mainfrom
fix/nested-closure-reverse
Draft

piercifani wants to merge 1 commit into
mainfrom
fix/nested-closure-reverse

Conversation

@piercifani

Copy link
Copy Markdown
Contributor

Requires skiptools/skipstone#305. CI will fail until a skipstone release contains it. This PR stays a draft until then, and will then bump the skip dependency the same way #109 did.

#109 covered a Swift-declared closure property set from Kotlin and called from Swift. This PR adds runtime coverage for the other bridging directions of closures whose parameters are closures, along with the exact signature from #101.

Kotlin-compat samples (Swift types bridged to Kotlin):

  • testCompatNestedClosureSetFromKotlin: onDeposit: @MainActor (@escaping @MainActor () -> Void) -> Void, set from Kotlin and called from Swift (the Complex closure crashes when being executed #101 case).
  • testCompatNestedClosureCalledFromKotlin: Swift-provided closures called from Kotlin with Kotlin lambdas: onDeposit, one that returns a value ((Int, @escaping (Int) -> String) -> String), and an optional one.

BridgeToSwift samples (Kotlin types bridged to Swift):

  • testNestedClosureVar: a Kotlin-native kotlinNestedClosureVar called from Swift with a Swift closure, then reassigned from Swift and called from Kotlin with a Kotlin lambda.

Testing

Run against a local build of skipstone#305, using SKIPLOCAL and a local skip checkout:

  • BridgeToKotlinCompatTests: 9/9 JUnit tests pass
  • BridgeToSwiftTests: 71/71 JUnit tests pass

Against skipstone 1.9.16, testCompatNestedClosureCalledFromKotlin crashes with Fatal error: Unable to bridge Kotlin/Java instance.

Closes #101

🤖 Generated with Claude Code

Add samples and tests for closures whose parameters are closures:

- Kotlin-compat: the @mainactor onDeposit signature from #101 set from
  Kotlin and called from Swift, and Swift-provided closures called from
  Kotlin with Kotlin lambdas (including a returning and an optional one)
- BridgeToSwift: a Kotlin-native closure var called from Swift with a Swift
  closure, then reassigned from Swift and called from Kotlin

Requires skiptools/skipstone#305.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cla-bot cla-bot Bot added the cla-signed label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complex closure crashes when being executed

1 participant