dual with statement
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 24 13:27:15 PDT 2014
monarch_dodra:
> From what I can observe, the compiler resolves the ambiguity by
> chosing the first match in terms of scope. Eg, there's
> shadowing. From my previous code:
>
>
>
> with (t)
> {
> writeln(k); //prints t.k
> with(s)
> {
> writeln(k); //prints s.k: it is now shadowing t.k
A reduced test case:
void main() {
static struct S { int k = 1; }
static struct T { int k = 2; }
S s;
T t;
with (t) {
assert(k == 2);
with(s) {
assert(k == 1);
}
}
}
Is this a failure (a bug) of the anti-hijacking mechanism of
with()?
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list