In implementing SDC I find myself asking these questions, and I wish to try and put and end to DMD being the sole definer of semantics; just letting you know the reason for this and subsequent bug reports. Given a series of with statements: with (a) with (b) with (c) { d(); } If all three objects have a method d(), then c gets called. Obviously the with statements are considered in a LIFO order, and the sentence http://www.digitalmars.com/d/2.0/statement.html#WithStatement "Use of with object symbols that shadow local symbols with the same identifier are not allowed. " does not apply here. Neither is documented behaviour, and the only to figure out how D behaves is to run DMD.
This is a compiler bug. Symbols used in with should shadow symbols from other with statements. You're right however, that the spec should state this.
(In reply to comment #1) > Symbols used in with should shadow symbols from other > with statements. Do you mean "shouldn't"? This shadowing is not detected, and I think the compiler has to flag this is as a compile error (just like it does with normal variables in the function stack frame): struct X { int a; } struct Y { int a; } void main() { X x; Y y; with (x) { a = 2; with (y) { a = 1; } } assert(x.a == 2); }
(In reply to comment #2) > (In reply to comment #1) > > Symbols used in with should shadow symbols from other > > with statements. > > Do you mean "shouldn't"? Yes and no. It shouldn't silently do so, but it should detect that that is what is happening, and cry out loudly.
The spec looks correct to me. The lookup order is not undefined, each successive with introduces a new scope which overrides previous scopes. As for the shadowing, that is a bug in the compiler.
Doesn't seem to be a problem anymore