Issue 23586 - DMD forgets a variable was just declared.
Summary: DMD forgets a variable was just declared.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2022-12-27 23:20 UTC by deadalnix
Modified: 2022-12-28 11:02 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description deadalnix 2022-12-27 23:20:04 UTC
Sample code:

int foo(int x) {
    switch(x) {
        case 0:
            goto Bar;

        Bar:
        default:
            auto y = 6;
            return y;
    }
}

void main() {
    auto x = foo(0);
}

What I get:
Error: undefined identifier `y`

What I expect:
The compiler to remember the variable was declared the line immediately above and use that.
Comment 1 Iain Buclaw 2022-12-27 23:54:19 UTC
Of course the workaround is just to swap the label and the default case.
Comment 2 Dlang Bot 2022-12-28 00:51:03 UTC
@ibuclaw created dlang/dmd pull request #14747 "fix Issue 23586 - DMD forgets a variable was just declared" fixing this issue:

- fix Issue 23586 - DMD forgets a variable was just declared

https://github.com/dlang/dmd/pull/14747
Comment 3 Dlang Bot 2022-12-28 11:02:35 UTC
dlang/dmd pull request #14747 "fix Issue 23586 - DMD forgets a variable was just declared" was merged into master:

- e842284b8e0855d8bda6006e2758a1bfa56c69af by Iain Buclaw:
  fix Issue 23586 - DMD forgets a variable was just declared

https://github.com/dlang/dmd/pull/14747