Comment #0 by andrej.mitrovich — 2019-10-02T02:07:19Z
-----
import std.stdio;
struct Set
{
int[int] set;
auto walk () { return this.set.byKey(); }
alias walk this;
}
void main()
{
Set set;
set.set[1] = 10;
writefln("Set contents: %s", set.set.byKey()); // ok
writefln("Set contents: %s", set); // prints "1" infinitely
}
-----
Tested with v2.086.1 and v2.088.0
Comment #1 by bugzilla — 2019-12-03T10:09:45Z
I think, the bug is to be found in dmd and byKey is innocent. If not, the correct component is not phobos but druntime, because byKey is located there.
Comment #2 by andrej.mitrovich — 2022-07-07T13:25:29Z
Simpler example:
-----
import std.stdio;
import std.range;
struct Set
{
auto walk () { return [].only; }
alias walk this;
}
void main()
{
Set set;
writeln(set);
}
-----
It has to do with ranges, not specifically hashmaps as previously thought.
I think somewhere in the formatter it's probably trying to invoke walk() multiple times, implicitly through that 'alias this'.
Comment #3 by robert.schadek — 2024-12-13T19:05:45Z