Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias this produces an infinite range when used with ranges #19625

Open
dlangBugzillaToGithub opened this issue Oct 2, 2019 · 2 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

Andrej Mitrovic (@AndrejMitrovic) reported this on 2019-10-02T02:07:19Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20258

CC List

Description

-----
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
@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

andrej.mitrovich (@AndrejMitrovic) commented on 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'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant