https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
n

n8ebel

10/30/2023, 10:11 PM
We've got some code in our shared Android + iOS network stack that is trying to map specific Throwable types to instance of a domain error class. This example is an over-simplification of what we're trying to do
Copy code
class CustomThrowable : Throwable()

internal fun Throwable.toNetworkError(): NetworkErrors {
    return if (this is CustomThrowable) {
        NetworkErrors.CustomErrorType()
    } else if (this is IOException) { // io.ktor.utils.io.errors.IOException
        NetworkErrors.OtherErrorType()
    } else {
        NetworkErrors.UnknownError()
    }
}
Our code was working fine until upgrading to kotlin 1.9.x, but after upgrading the Kotlin version we now get compiler errors that look like this
Copy code
e: org.jetbrains.kotlin.konan.KonanExternalToolFailure: The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ command returned non-zero exit code: 70.
output:
Instruction does not dominate all uses!
  %1740 = phi %struct.ObjHeader* [ %1739, %landingpad ], [ %1045, %landingpad444 ], [ %1461, %landingpad455 ], !dbg !152500
  %3026 = call fastcc %struct.ObjHeader* @"kfun:com.premise.network.core#toNetworkError__at__kotlin.Throwable(){}com.premise.network.core.NetworkErrors"(%struct.ObjHeader* %1740, %struct.ObjHeader** nonnull %254), !dbg !152892
I've tried all kinds of variations of the code to see if I can make the compiler happy, but with no luck. If we try to check that our Throwable is a Throwable, the code compiles. Checking if it's any other type, whether one we defined or coming from Ktor, causes this failure. Has anyone experienced something similar? Any clue as to what changed between Kotlin 1.8 to 1.9 that would cause our code to no longer compile would be really helpful.
😯 2
2 Views