Kotlin

Kotlin

Made by DeepSource

Return values must not be ignored KT-E1008

Bug risk
Minor

Ignoring the return value of functions in Kotlin is generally discouraged because it can lead to unintended consequences and make the code harder to understand and maintain. Ignoring the return value means that valuable data might be discarded, which could be crucial for the program's logic or correctness. Besides, certain functions may return resources like file handles or network connections. Ignoring the return value without properly handling and releasing those resources can lead to resource leaks, which can be detrimental to the application's performance.

Bad Practice

fun postUpdate(): Result<Post, Throwable> {
    // ..
}

postUpdate() // Return value is completely ignored.

Recommended

Consider using the return value, because there's a reason why the function returned a value in the first place.

fun postUpdate(): Result<Post, Throwable> {
    // ..
}

val result = postUpdate() // Do something with result.