with and shadowing variables
Anonymouse
asdf at asdf.net
Tue Jul 24 15:54:19 UTC 2018
On Monday, 23 July 2018 at 17:26:16 UTC, Steven Schveighoffer
wrote:
> On 7/22/18 8:13 AM, Anonymouse 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.
>
> I'm with Jonathan, it should be an error. It shouldn't matter
> what scope you declared `i` in, just when you use it, the
> ambiguity should trigger. The fix is super-simple, name it
> something else!
Filed as https://issues.dlang.org/show_bug.cgi?id=19113.
More information about the Digitalmars-d
mailing list