Issue with algorithm.fold - dmd hangs
monkyyy
crazymonkyyy at gmail.com
Fri Apr 4 23:51:19 UTC 2025
On Friday, 4 April 2025 at 23:35:14 UTC, Borax Man wrote:
>
> Sorry if this is an actual bug with DMD. I suspect it might
> be, but I'm not sure whether the fault is DMD or my code.
>
> Short story, I wrote a program for work to do calculations for
> my team in D, and use Windows 64bit DMD to compile. I upgraded
> to the latest DMD, and its hangs on compile. I tried under
> Linux, and same issue.
>
> Verison is
>
> DMD64 D Compiler v2.111.0
> Copyright (C) 1999-2025 by The D Language Foundation, All
> Rights Reserved written by Walter Bright
>
> When I compile using dmd with the "-v" switch, these are the
> last messages.
>
> import
> core.internal.string (/usr/include/dmd/druntime/import/core/internal/string.d)
> semantic3 foldtest
> import std.utf (/usr/include/dmd/phobos/std/utf.d)
> import
> std.algorithm.internal (/usr/include/dmd/phobos/std/algorithm/internal.d)
>
> It hangs at the last line, just stays there consuming CPU
> cycles.
>
> I've extracted a minimal failing copy. The line which calls
> "fold" to sum the values causes it to hang. This compiles fine
> with GDC and LDC2, and worked with DMD version before 2.100 (I
> didn't try anything between 2.100 and 2.111.0)
>
> Is my code wrong, or have I stumbled on a bug?
>
> Code below
>
> ==================================================
>
> import std.algorithm;
> import std.range;
> import std.stdio;
>
> final class DataClass {
> private:
> int x;
>
> this()
> {}
> this(in int _x)
> {
> x=_x;
> }
>
> auto ref opOpAssign(string op : "+")(in DataClass other)
> {
> x += other.x;
> return this;
> }
>
> void printx()
> {
> writeln(x);
> }
>
> auto opBinary(string op : "+")(in DataClass other)
> {
> DataClass newr = new DataClass();
> newr.x = x + other.x;
> return newr;
> }
> }
>
> int main()
> {
> DataClass[] dataclassarray;
> DataClass result = new DataClass();
> DataClass d1 = new DataClass(3);
> DataClass d2 = new DataClass(4);
> DataClass d3= new DataClass(10);
> DataClass d4 = new DataClass(12);
> DataClass res2 = new DataClass(10);
> dataclassarray~=d1;
> dataclassarray~=d2;
> dataclassarray~=d3;
> dataclassarray~=d4;
> res2 += d1; // This works
> res2.printx();
> res2 = d1 + d2; // This works
> res2.printx();
> result = dataclassarray.fold!((a,b) => a + b); // This causes
> dmd to hang.
> result.printx();
> return 0;
> }
works for me
More information about the Digitalmars-d
mailing list