dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Deprecate using an unqualified symbol defined in a `do`–`while` loop in its condition

Open Bolpat opened this issue 5 months ago • 0 comments

When a symbol (usually a variable) is defined in the body of a dowhile loop, it’s not in scope anymore in the condition. That means, the name of the symbol might refer to a different symbol in some outer scope (e.g. a member or global variable). That use should be deprecated. It’s almost certainly a bug, and if it’s not, it can be clarified using this.name or .name.

int x;
struct S
{
    int y;
    void f()
    {
        do
        {
            int x, y;
            …;
        }
        while (x > y); // likely a bug
    }
}

In the example above, one would have to change the condition to while (.x > this.y) or rename the local variables.

Bolpat avatar Jul 28 '25 10:07 Bolpat