Skip to content

BSL051 — Unreachable Code

Summary

Unreachable Code

Identifiers

Field Value
Rule code BSL051
Compatible alias UnreachableCode
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags suspicious, dead-code

Behavior

  • The public identifier BSL051 and alias UnreachableCode are stable.
  • The rule reports the cases documented on this page.
  • Suppressions and project configuration are applied before publication.
  • The rule requires neither an external analyzer nor network access.

Configuration and suppression

BSL### is the primary stable identifier. The compatible alias is accepted in select, ignore, and compatible block suppression comments.

[tool.onec-hbk-bsl]
select = ["BSL051"]
ignore = ["UnreachableCode"]

All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:

  • noqa:
Value = "example";  // noqa: BSL051
  • bsl-disable:
Value = "example";  // bsl-disable: BSL051
  • compatible BSLLS form:
Value = "example";  // BSLLS:UnreachableCode-off

When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:

// noqa: BSL051
// code without this diagnostic
// noqa-enable: BSL051

// bsl-disable: BSL051
// code without this diagnostic
// bsl-enable: BSL051

// BSLLS:UnreachableCode-off
// code without this diagnostic
// BSLLS:UnreachableCode-on

To disable the rule until the end of the file, omit the closing noqa-enable, bsl-enable, or BSLLS:…-on marker.

Opening and closing markers must belong to the same family.

Description

Code located after operators "Return", "GoTo", "Raise", "Break", "Continue" never will be executed.

Errors of unreachable code can be caused by developer carelessness when editing another's code.

Examples

Procedure Example()
    Return;
    // Code below operator Return will never be executed
    For each Line from Lines Do
        If Condition2 Then
            Method();
        EndIf;
    EndDo;
EndProcedure
Function Example(Parameter1, Parameter2)
    If Error Then
        Raise "Error occurred";
        // After rise exception the code bellow will be ignored
        Parameter1 = Parameter2;
    EndIf;
    Return Parameter1;
EndFunction