Bug 23586 – DMD forgets a variable was just declared.

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-12-27T23:20:04Z
Last change time
2022-12-28T11:02:35Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
deadalnix

Comments

Comment #0 by deadalnix — 2022-12-27T23:20:04Z
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 by ibuclaw — 2022-12-27T23:54:19Z
Of course the workaround is just to swap the label and the default case.
Comment #2 by dlang-bot — 2022-12-28T00:51:03Z
@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 by dlang-bot — 2022-12-28T11:02:35Z
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