[Issue 603] New: Undocumented behaviour: case and default create a scope
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Nov 26 06:22:22 PST 2006
http://d.puremagic.com/issues/show_bug.cgi?id=603
Summary: Undocumented behaviour: case and default create a scope
Product: D
Version: 0.175
Platform: PC
URL: http://www.digitalmars.com/d/statement.html#SwitchStatem
ent
OS/Version: Windows
Status: NEW
Keywords: rejects-valid, spec
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: smjg at iname.com
I've noticed an interesting behaviour: the code between two consecutive case or
default labels creates a scope.
----------
import std.stdio;
void main() {
int qwert;
switch (qwert) {
case 42:
int yuiop;
int asdfg;
default:
int hjkl = 98;
writefln(yuiop);
writefln(asdfg);
writefln(hjkl);
}
}
----------
D:\My Documents\Programming\D\Tests\label_scope_2.d(12): Error: undefined
identifier yuiop
D:\My Documents\Programming\D\Tests\label_scope_2.d(13): Error: undefined
identifier asdfg
----------
While this is intuitively sensible (it enables cases to define their own
variables independently of each other), it doesn't follow from the logical code
structure (in which all cases are at one level immediately below the
SwitchStatement) or from anything on the relevant page of the spec.
--
More information about the Digitalmars-d-bugs
mailing list