Bug 4902 – No label and variable with the same name error

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2010-09-20T18:00:10Z
Last change time
2024-12-13T17:53:22Z
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18300 →

Comments

Comment #0 by bearophile_hugs — 2010-09-20T18:00:10Z
This compiles with no errors, but maybe it's better to refuse (and show an error) when a label has the same name of a variable: enum int FOO = 1; int main() { goto FOO; FOO: return FOO; } That helps keep code tidy, and also helps to avoid probably wrong code like (note the missing 'case'): enum int CONST1 = 1; enum int CONST2 = 2; void main() { int x = 1; switch (x) { case CONST1: break; CONST2: break; default: break; } } Something similar toi the second situation is present among the Semantic Errors of Java code in the Google Web Toolkit too: http://code.google.com/intl/en-EN/webtoolkit/tools/codepro/doc/features/audit/audit_rules_com.instantiations.assist.eclipse.auditGroup.possibleErrors.html#com.instantiations.assist.eclipse.audit.nonCaseLabelInSwitch
Comment #1 by bearophile_hugs — 2010-09-20T18:01:57Z
So far in my code I have never had a bug caused by this, so I consider this low-priority.
Comment #2 by robert.schadek — 2024-12-13T17:53:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18300 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB