Looking to exchange some ideas around a strange KM...
# multiplatform
a
Looking to exchange some ideas around a strange KMM behaviour. We had this function in a commonMain source for Android and iOS code;
Copy code
private fun String.strip() = this
    .replace(oldValue = "https://", newValue = "", ignoreCase = true)
    .replace(oldValue = "http://", newValue = "", ignoreCase = true)
    .substringBefore(delimiter = "?")
which was called from the same file on a String. This has been working fine until recently. Now suddenly, the function does nothing ("https://" prefix is not removed from a string) on Android but works like before on iOS. I think it was after bumping to Kotlin 1.7.20, AGP 7.3 and compileSdk 33. What could be happening here? Theory: Is something causing it to call through to the Java String.strip() function instead, which was added in Java 11? Does it have to do with desugaring?
m
Oh good to know - did you report that? Does that occurs without KMP? What is with Kotlin 1.7.21?
a
I have not reported this yet
Do not yet know if it happens without KMP, or if there is a change with 1.7.21
The behaviour is the same with Kotlin 1.7.21
I've made a minimum reproducible example and it appears to be triggered by changing to compileSdk = 33 in the kmp module. However, in my repro code project I get a warning in the IDE to not use ".strip()" which I didnt get in my main project...
I also get a warning on my definition of my extension function, which I didnt get in the other project either
of course, none of those warnings help on old code that continues to compile when bumping from compileSdk = 32 to compileSdk = 33.
This problem in itself is in fact not related to KMP/KMM, other than that behaviour is different when compiled via KMP to iOS
It isnt caused by desugaring, by the way, Ive tried with that both on and off and the behavior is the same
Ok so after some reading, this is by design: https://kotlinlang.org/docs/extensions.html#extensions-are-resolved-statically "The member always wins" And unfortunately for us, we used a too generic name for the function ("strip") and its been added somehow when using compileSdk = 33, so it wins. In my opinion that should have caused a compile error.