Bug 20258 – alias this produces an infinite range when used with ranges

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-10-02T02:07:19Z
Last change time
2024-12-13T19:05:45Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: dmd#19625 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19625 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB