Our website uses cookies to enhance your browsing experience.
Accept
to the top

Webinar: Let's make a programming language. Lexer - 29.04

>
>
>
V8004. The use of 'if A {...} else...
menu mobile close menu
Additional information
toggle menu Contents

V8004. The use of 'if A {...} else if A {...}' pattern was detected. Potential logical error is present.

Apr 03 2026

The analyzer has detected a potential error in a construction consisting of conditional instructions. The error is caused by repeated if conditions, which may result in the code within that branch becoming unreachable.

The example:

const (
  MONDAY    = "Monday"
  TUESDAY   = "Tuesday"
  WEDNESDAY = "Wednesday"
  THURSDAY  = "Thursday"
  FRIDAY    = "Friday"
)

if day == MONDAY {
  ....
} else if day == TUESDAY {
  ....
} else if day == WEDNESDAY {
  ....
} else if day == THURSDAY {
  ....
} else if day == MONDAY {
  ....
}

In the example, there are two if constructions with the same condition. If control flow reaches the second condition, it will always evaluate as false, making all code in the corresponding branch unreachable.

The fixed code:

if day == MONDAY {
  ....
} else if day == TUESDAY {
  ....
} else if day == WEDNESDAY {
  ....
} else if day == THURSDAY {

} else if day == FRIDAY {
  ....
}