A property's getter reads the property, or its setter assigns it, instead of field

tx0/kotlin:recursive-property-accessorrecommendederrorreliability/object-contractsdepth fastbug

What it finds

var name: String = "" set(value) { name = value.trim() } calls the setter again from inside the setter, and val size: Int get() = size calls the getter from the getter: both recurse until the stack overflows. Inside an accessor, field is the stored value.

From the rule's source, recursive_accessor.rs.

Example from the rule's tests
class Person {    var name: String = ""        set(value) {            name = value.trim()tx0 reports: the setter assigns name itself        }    val size: Int        get() = size + 1tx0 reports: the getter reads size itself    val Int.twice: Int        get() = twice    var age: Int = 0        set(value) {            field = value.coerceAtLeast(0)        }    val label: String        get() {            val name = "local"            return name        }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:recursive-property-accessor" = "error"

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:recursive-property-accessor] reason="..."

tx0 explain tx0/kotlin:recursive-property-accessor shows the same in the terminal. Found a false positive? Report it.