An assignment writes back the value the variable already holds

tx0/kotlin:self-assignmentdefaultwarningreliability/logicdepth fastbug

What it finds

count = count or this.name = this.name changes nothing, which usually means that the right side was meant to be something else, such as a parameter of the same name.

Reported for local variables and parameters, and for properties declared in the file without a custom setter. Other properties are left alone, since assigning one may run a setter on purpose, as view.layoutParams = view.layoutParams does on Android.

From the rule's source, self_assignment.rs.

Example from the rule's tests
class Box(var width: Int) {    var height = 0    var depth = 0        set(value) {            field = value            redraw()        }     fun resize(width: Int, view: View) {        var local = width        local = localtx0 reports: local is assigned to itself        this.height = this.heighttx0 reports: this.height is assigned to itself        height = heighttx0 reports: height is assigned to itself        this.width = width        depth = depth        view.layoutParams = view.layoutParams    }}
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 in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:self-assignment" = "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:self-assignment] reason="..."

tx0 explain tx0/kotlin:self-assignment shows the same in the terminal. Found a false positive? Report it.