https://issues.dlang.org/show_bug.cgi?id=18698
Simen Kjaeraas <simen.kja...@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |simen.kja...@gmail.com --- Comment #17 from Simen Kjaeraas <simen.kja...@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. --