Skip to content

fix optional Int JNI conversion#751

Merged
ktoso merged 1 commit into
swiftlang:mainfrom
nerzh:fix/jlong-otional-int-for-v7a
May 15, 2026
Merged

fix optional Int JNI conversion#751
ktoso merged 1 commit into
swiftlang:mainfrom
nerzh:fix/jlong-otional-int-for-v7a

Conversation

@nerzh
Copy link
Copy Markdown
Contributor

@nerzh nerzh commented May 14, 2026

I noticed that Int? / UInt? JNI bindings did not use the same 32-bit-safe conversion path as plain Int / UInt. I fixed it by routing optional values through the existing indirect conversion and overflow checks 🫣

/oberton-wallet-core/.build/plugins/outputs/cust-wallet-core/CustWalletCore/destination/JExtractSwiftPlugin/Sources/AbiTypes+SwiftJava.swift:3755:28: error: cannot assign value of type 'Int.JNIType' (aka 'Int32') to type 'jlong' (aka 'Int64')
3753 |   let result$: jlong
3754 |   if let innerResult$ = selfPointer$.pointee.balance {
3755 |     result$ = innerResult$.getJNIValue(in: environment)
     |                            `- error: cannot assign value of type 'Int.JNIType' (aka 'Int32') to type 'jlong' (aka 'Int64')
3756 |     var flag$ = Int8(1)
3757 |     environment.interface.SetByteArrayRegion(environment, result_discriminator$, 0, 1, &flag$)

/oberton-wallet-core/ObertonWalletCore/destination/JExtractSwiftPlugin/Sources/AbiTypes+SwiftJava.swift:3778:77: error: cannot convert value of type 'jlong' (aka 'Int64') to expected argument type 'Int.JNIType' (aka 'Int32')
3776 |     fatalError("selfPointer memory address was null in call to \(#function)!")
3777 |   }
3778 |   selfPointer$.pointee.balance = newValue_discriminator == 1 ? Int(fromJNI: newValue_value, in: environment) : nil
     |                                                                             `- error: cannot convert value of type 'jlong' (aka 'Int64') to expected argument type 'Int.JNIType' (aka 'Int32')
3779 | } // printCDecl(_:javaMethodName:parentName:parameters:resultType:_:) @ JExtractSwiftLib/JNISwift2JavaGenerator+SwiftThunkPrinting.swift:818
3780 | 

@nerzh nerzh requested a review from ktoso as a code owner May 14, 2026 19:43
Copy link
Copy Markdown
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you for catching this and the fix!

@ktoso ktoso merged commit bd02506 into swiftlang:main May 15, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants