[Issue 1849] with() should cause shadowing errors if you use a member that's shadowed

Christopher Wright dhasenan at gmail.com
Wed Mar 5 05:44:18 PST 2008


d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1849
> 
> 
> 
> 
> 
> ------- Comment #6 from wbaxter at gmail.com  2008-03-04 21:10 -------
> (In reply to comment #5)
>> I agree it can be a problem, and some people argue that the with itself is
>> inherently a bad construct for such reasons. They might be right.
> 
> They may be.  If there were a way to do "selective with" like selective import
> I would probably use that.
>    with(BigObject : member, other_member) { ... }
> 
> Or if I could alias dot expressions like:
>   alias foo.bar bar
> 
> then I wouldn't be tempted to use 'with' as often.

If you could explicitly say that something is in an external scope, that 
would also help. For instance:

struct Foo { int a; }

Foo myStruct;
int a = 15;
with (myStruct)
{
    a = .a;
    // myStruct.a == 15
}

Or simply saying any ambiguity is a compile-time error.


More information about the Digitalmars-d-bugs mailing list