how is this array subtyping inside struct (bug?) possible?
snarwin at gmail.com
Mon Aug 10 15:40:19 UTC 2020
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()?
foreach over a range also uses front() and popFront().
> Why is it modifying something it knows to be a class? This is
> definitely a bug that should be fixed.
The behavior of writeln in this case is documented under
`std.format.formatValue` , which is used by `writeln`
> For the class objects which have input range interface,
> * If the instance toString has overridden Object.toString,
> it is used.
> * Otherwise, the objects are formatted as input range.
So everything is working as intended. However, there is certainly
a documentation issue here, since it is not at all obvious from
the `writeln` docs that it uses `formatValue`.
More information about the Digitalmars-d