A function calls itself with its own arguments before doing anything else, and never returns
What it finds
fun size(): Int = size() and a function whose first statement is a call to itself with the same arguments recurse until the stack overflows. This is often a member that meant to delegate to a field or to super. Functions with annotations, expect and actual functions, and names that the file also imports are left out, as the call may pick another function of the same name. So are calls whose name is a parameter or local variable in scope, as override fun decode(v) = decode(v) inside a function that takes a lambda decode: in Kotlin the nearer name wins, and that is no recursion.
From the rule's source, unconditional_self_call.rs.
class Box(private val items: List<Int>) { fun size(): Int = size()tx0 reports: size calls itself with the same arguments and never returns fun get(index: Int): Int { return get(index)tx0 reports: get calls itself } fun count(n: Int): Int = if (n == 0) 0 else count(n - 1) fun find(x: Int): Int = find(x + 1)} inline fun <T : Any> adapter(crossinline decode: (String) -> T, crossinline encode: (T) -> String) = object : ColumnAdapter<T, String> { override fun decode(databaseValue: String): T = decode(databaseValue) override fun encode(value: T): String = encode(value) } fun newAsyncListener(onComplete: (AsyncEvent) -> Unit) = object : AsyncListener { override fun onComplete(event: AsyncEvent) = onComplete(event)} fun run(block: () -> Unit) { val handle = { e: Int -> println(e) } val task = object : Task { override fun handle(e: Int) = handle(e) } task.handle(1) block()} fun twice(twice: () -> Unit) = twice() Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/kotlin:unconditional-self-call" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:unconditional-self-call] reason="..."tx0 explain tx0/kotlin:unconditional-self-call shows the same in the terminal. Found a false positive? Report it.