how is this array subtyping inside struct (bug?) possible?
mingwu at gmail.com
Mon Aug 10 21:20:11 UTC 2020
On Monday, 10 August 2020 at 20:42:34 UTC, Steven Schveighoffer
> On 8/10/20 4:13 PM, mw wrote:
>>>> This defeats the purpose, i.e. the convenience that
>>>> subtyping mechanism supposed to provide.
>>> You are subtyping but inadvertently have turned a forward
>>> range (array) into an input range (iterate only once) by
>>> changing it into a class.
>> This subtyping loophole should be fixed by the compiler.
> No, it is doing exactly what you asked it to do -- turn a
> non-reference type into a full reference type.
Sorry, I typed too quickly, I'm trying to say: by the
__compiler__ -> by the std library.
> The fault here is Phobos for accepting classes as ranges (range
> classes are IMO an abomination that should never be used).
Yes, it's the library did it wrong, I still hold the opinion that:
`writeln` should be a *view* (i.e read-only) function, it
shouldn't *internally* call anything thing that change the data
More information about the Digitalmars-d