April 01, 2018
https://issues.dlang.org/show_bug.cgi?id=18698

--- Comment #11 from Ketmar Dark <ketmar@ketmar.no-ip.org> ---
  module test;
  foreach(m; __traits(allMembers, test))
  {
    pragma(msg, m);
  }

rdmd --force --compiler=ldc --eval="pragma(msg, __VERSION__);"
2073L

rdmd --force --compiler=ldc -c test.d
test.d(2): Error: declaration expected, not 'foreach'
test.d(2): Error: declaration expected, not '__traits'
test.d(5): Error: unrecognized declaration

2.073 is *way* before `static foreach`.

so please, code sample and compiler version. if it used to work, and now doesn't, this is clearly a regression nobody noticed.

the same for old `foreach` code that doesn't work as it used to work before, please.

--
April 01, 2018
https://issues.dlang.org/show_bug.cgi?id=18698

--- Comment #12 from Manu <turkeyman@gmail.com> ---
I'd love to paste code... But I wrote it in 2012 at a company I don't work at
anymore.
Think D2.042...

I'll see what I can do when I'm not in bed on a phone. But I have no idea what now I can offer. I used to take function prototypes at top level, and mixin their bodies at the same scope. My entire system was based on this.

They didn't fly me to dconf to talk about code that didn't compile.

--
April 01, 2018
https://issues.dlang.org/show_bug.cgi?id=18698

--- Comment #13 from Ketmar Dark <ketmar@ketmar.no-ip.org> ---
>Think D2.042
easy deal: http://downloads.dlang.org/releases/2010/

[pts/44:ketmar]:D/_old_dmd% ./dmd2/linux/bin/dmd
Digital Mars D Compiler v2.042
Copyright (c) 1999-2010 by Digital Mars written by Walter Bright

[pts/44:ketmar]:D/_old_dmd% ./dmd2/linux/bin/dmd -c test.d
test.d(2): Declaration expected, not 'foreach'
test.d(2): Declaration expected, not '__traits'
test.d(5): unrecognized declaration

exactly the same error with 2.039. should i go even further back in time? or, fast-forward to 2.059: still the same thing. it. never. worked.

--
April 01, 2018
https://issues.dlang.org/show_bug.cgi?id=18698

Seb <greensunny12@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12@gmail.com

--- Comment #14 from Seb <greensunny12@gmail.com> ---
Here's the regression tester with all 19 versions from 2.060 to 2.079:

https://run.dlang.io/is/ZBosCr

Anyhow, I think we all agree that Manu's use case should work, so let's focus on fixing that (and avoid the off-topic discussion whether this may or may nor have worked a long time ago).

--
April 01, 2018
https://issues.dlang.org/show_bug.cgi?id=18698

--- Comment #15 from Manu <turkeyman@gmail.com> ---
Okay, I must have had some workaround... I don't remember what exactly, it was
some years ago. I probably wrapped it in layers until it worked.
Regardless, it should work. My colleague just tried to do this and asked me why
it didn't work...
I have no recollection of workarounds I might have used.

--
April 10, 2018
https://issues.dlang.org/show_bug.cgi?id=18698

--- Comment #16 from Manu <turkeyman@gmail.com> ---
I remember my work-around; I ran the foreach inside a static module constructor!
>From there I generated my reflection information about the module and
registered it at runtime (in the module constructor), rather than emit data directly into the module scope.

In this instance, I really need to emit functions into the module scope, and
not do runtime registration like I did last time.
It would be really really nice to fix this issue!

--
April 11, 2018
https://issues.dlang.org/show_bug.cgi?id=18698

Simen Kjaeraas <simen.kjaras@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras@gmail.com

--- Comment #17 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
As a workaround for now, you can use a string mixin:


import std.conv : to;
string create() {
    string s = "";
    static foreach (i, e; __traits(allMembers, mixin(__MODULE__))) {
        s ~= "int n"~i.to!string~";";
    }
    return s;
}
mixin(create());
pragma(msg, __traits(allMembers, mixin(__MODULE__))); // tuple("object",
"create", "n0", "n1")


The root cause is, as Ketmar pointed out in comment #2, that __traits(allMembers) tries to expand the static foreach, and the static foreach calls __traits(allMembers), leading to unbounded mutual recursion and eventually a stack overflow. The exact same issue occurs if a template mixin in used in place of the string mixin in the above example.

This makes some sense - how can you iterate over all members when the list isn't complete yet? For the sake of pragmatism though, it's probably sensible to allow iteration of the incomplete list, and certainly having the compiler crash is less than optimal.

--
June 10, 2019
https://issues.dlang.org/show_bug.cgi?id=18698

Nicholas Wilson <iamthewilsonator@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |iamthewilsonator@hotmail.co
                   |                            |m
         Resolution|---                         |WORKSFORME

--- Comment #18 from Nicholas Wilson <iamthewilsonator@hotmail.com> ---
This works now, test case added in https://github.com/dlang/dmd/pull/10016

--
1 2
Next ›   Last »