with and shadowing variables

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Jul 22 14:05:45 UTC 2018


On Sunday, July 22, 2018 12:13:43 Anonymouse via Digitalmars-d wrote:
> Can this be made a compiler warning?
>
> struct Foo
> {
>      int i;
> }
>
> void main()
> {
>      Foo foo;
>
>      with (foo)
>      {
>          i = 42;
>          int i;
>          i = 24;
>      }
> }
>
> I'm hesitant to file a bug because it'll just be immediately
> closed with a link to
> https://dlang.org/spec/statement.html#WithStatement. I understand
> that's how it works, but it's weird and weak to human mistakes.

Given the shadowing protections listed in #5, it could certainly be argued
that it would be in the spirit of the restrictions that with already has,
and I think that there's a pretty clear argument to be made that allowing it
is too error-prone, but maybe someone will have a reason why it doesn't make
sense to disallow it. I don't know. Regardless, I would suggest that you
open an enhancement request. I would guess that it's straightforward enough
that a DIP isn't reauired so long as Walter approves of it, but I don't
know. Either way, if it's in bugzilla, then it stands a much better chance
of happening than if the only record of it is here.

- Jonathan M Davis



More information about the Digitalmars-d mailing list