On Monday, 11 March 2013 at 22:08:10 UTC, H. S. Teoh wrote:
On Mon, Mar 11, 2013 at 10:31:53PM +0100, Timon Gehr wrote:
On 03/11/2013 09:19 PM, Jonathan M Davis wrote:
>On Monday, March 11, 2013 20:14:07 Timon Gehr wrote:
>>Actually, in D, static if creates its own scopes for
>>declarations
>>made inside the static if condition.
>
>No, it doesn't,
Yes it does.
Actually, it doesn't, scarily enough:
import std.stdio;
void main() {
int[string] x;
//float x;
static if (is(typeof(x) S : T[U], T, U)) {
writeln(S.stringof);
writeln(T.stringof);
writeln(U.stringof);
}
writeln(S.stringof); // <-- this compiles, and works!!
}
The last writeln will fail to compile if x's type is changed to
float
(as in the commented out line).
Meaning that the definitions of S, T, U "leak" past the scope
of the
static if. Which makes the semantics of the code very unclear,
because
whether or not it even compiles depends on how the static if
condition
turns out. :-/
T
I think that's bug material. The "is" definition should end at
the end of that block.