how is this array subtyping inside struct (bug?) possible?

mw mingwu at gmail.com
Mon Aug 10 18:33:58 UTC 2020


On Monday, 10 August 2020 at 15:36:35 UTC, Kagamin wrote:
> On Monday, 10 August 2020 at 13:44:17 UTC, Avrina wrote:
>> This really doesn't excuse why this bug is happening. Why is 
>> writeln() using front() and popFront() that modifies the range 
>> rather than simply using foreach()? Why is it modifying 
>> something it knows to be a class? This is definitely a bug 
>> that should be fixed. Not sure why people are trying to 
>> explain it away, looking that the writeln implementation it is 
>> completely convoluted. It's no wonder bugs like this are going 
>> to happen.
>
> When writeln receives a reference type range, are you sure it 
> shouldn't be consumed? How do you decide that?

Because `writeln` should be a *view* (i.e read-only) function, it 
shouldn't *internally* call anything thing that change the data 
passed in.

Only the user can *explicitly* change the data, and let writeln 
print it: e.g.
```
   writeln(data.change_And_Print_The_State_After_The_Change());
```



More information about the Digitalmars-d mailing list