Is there any support for warning/erroring on an un...
# getting-started
b
Is there any support for warning/erroring on an unused return value in kotlin? I found this thread https://discuss.kotlinlang.org/t/unused-result-warnings/602/5 but it's quite old, wondering if anything's changed since then. Everything I find when searching is related to unused arguments.
b
@CheckResult
is probably what are you looking for - https://developer.android.com/reference/android/support/annotation/CheckResult
b
yes exactly, but do you know of a non-android version?
k
Out of curiosity, what’s the use case for this?
b
for example, the following function:
Copy code
fun Byte.putBit(bitPos: Int, isSet: Boolean): Byte {
    return if (isSet) {
        (this.toInt() or (0b10000000 ushr bitPos)).toByte()
    } else {
        (this.toInt() and (0b10000000 ushr bitPos).inv()).toByte()
    }
}
it would be easy for someone to call
myByte.putBit(1, true)
and think it would be modified in place, but actually it returns the new value. i'm looking for a way similar to 'nodiscard' in c++ where i can generate a warning of some kind in this scenario