D's greatest mistakes

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Nov 29 13:43:01 PST 2010


On 11/29/10 3:25 PM, Manfred_Nowak wrote:
> Daniel Gibson wrote:
>
>> "with" shouldn't be much of a problem anymore.
>
> import std.stdio;
> struct X{ int a, b, c;}
> struct Y{ int a, b;}
> void main(){
>    X x;
>    Y y;
>    with( x){
>      c= 2;
>      with( y){
>        c= 1;
>      }
>    }
>    writeln( x.c);
> }
>
> Do you see the not "much of a problem"?
>
> -manfred

Great. Could you please submit this as a bug report?

In essence with should work as if this code was written:

with (value) statement

becomes

{
   auto field1 = value.field1;
   auto field2 = value.field1;
   ...
   auto fieldn = value.fieldn;
   statement
}

The rewritten code is not equivalent because the field names are really 
references, but they must obey the same visibility rules. If the 
rewritten code has any shadowing errors, the use of with should also be 
in error.


Andrei


More information about the Digitalmars-d mailing list