https://kotlinlang.org logo
Title
j

Jeff Lockhart

05/11/2023, 6:32 PM
I noticed the latest 1.9.0-Beta-104 includes this commit, which adds
@ExperimentalForeignApi
to Kotlin/Native kotlinx.cinterop APIs, like
CPointer
,
memScoped
,
alloc
,
convert
, as well as most C/ObjC interop generated APIs. Could someone please explain this change? Are apps that use C interop expected to opt in to this annotation globally?
j

jw

05/11/2023, 6:35 PM
The linked issue seems to cover it pretty well https://youtrack.jetbrains.com/issue/KT-57728
j

Jeff Lockhart

05/11/2023, 6:39 PM
Thanks, I was just beginning to read the issue. Probably should have done that before asking as it does explain things more.
So after reading the issue, it doesn't explicitly answer my question, but my assumption would be a project that requires these C/ObjC interop APIs does need to opt in to this
@ExperimentalForeignApi
annotation (as well as possibly the
@BetaInteropApi
warning), and does so with the knowledge that these APIs may change in the future, replaced by better designed and documented alternatives. I'm also assuming any such changes would come after KMM's stability announcement and Kotlin 2.0.
j

jw

05/11/2023, 7:26 PM
That's about my read. You already are subject to these semantics, it's just that they weren't communicated anywhere. The opt-in annotation forces that to be acknowledged, even if you suppress it globally.
j

Jeff Lockhart

05/11/2023, 7:41 PM
That makes sense. The documentation has definitely been lacking for these APIs, at least in the KDocs. But the documentation that does exist never explicitly mentions API stability, which I'm sure will be updated with this info for the 1.9 release. Good to know this will eventually improve, even if it does mean migrating some code in the future.