The same value is assigned to the variable again

  • Code Quality
  • Low
  • No tags

This rule applies when a variable is assigned with the same value as the following:

  1. Assignment made to same variable
  2. Redundant assignment
  3. Swapping the assignment with LHS and RHS variables

The above assignments can be unnecessary code, but they can be assigned with a wrong variable which is not likely to be a programmer's intent.

Noncompliant Code Example

View with compliant examples side by side
// Example 1
a = a; // ASSIGN_SAME_VALUE alarm

// Example 2
a = b;
a = b; // ASSIGN_SAME_VALUE alarm

// Example 3
r = a;
a = b;
b = a; // ASSIGN_SAME_VALUE alarm

Compliant Code Example

View with noncompliant examples side by side
// Example 3
r = a;
a = b;
b = r; // a and b are swapped


This rule was introduced in DeepScan 1.0.0-alpha.