Rules / self-assignment
Assigning a variable to itself, x := x, in Structured Text
The line x := x does nothing. It is almost always a typo: another variable was meant on the right, such as a setpoint from the HMI.
Severity: Warning
Rule id: self-assignment
Assignment of a variable to itself
What the rule checks
A line like x := x; assigns a variable to itself and does nothing. Usually a typo on the right-hand side (another variable was meant) or a leftover from deleted logic.
What it does to the plant
The value never updates: the setpoint is changed on the screen while the program keeps using the old one.
Example
PROGRAM SetpointsVAR rSetpoint : REAL; rSetpointHmi : REAL;END_VARrSetpoint := rSetpoint;
PROGRAM SetpointsVAR rSetpoint : REAL; rSetpointHmi : REAL;END_VARrSetpoint := rSetpointHmi;
Both listings are run through the linter by an automated test: the rule fires on the first and stays silent on the second.
How to fix
- The right-hand side probably should be another variable (a typo); check the intent.
- If the line is redundant, remove it.
Upload a PLCopen XML or CODESYS .export file: the report is free and the code is not stored.
The same linter without uploading a file: command line and GitHub Action.
Related rules
;; (empty statement) · double-semicolonUnused local variable · unused-localEmpty IF/loop branch · empty-branch
2026-11-26