import std.stdio;
string toConcatenatedForm(string m, string[] args...)
{
string result = "q{";
for (;;)
{
if (!m.length)
{
return result ~ '}';
}
if (m[0] != '$')
{
result ~= m[0];
m = m[1 .. $];
continue;
}
if (m[1] >= '1' && m[1] <= '9')
{
result ~= "} ~ ";
result ~= "expand!(q{" ~ args[m[1] - '1'] ~ "}) ~ q{";
m = m[2 .. $];
continue;
}
}
}
template expand(string m, args...)
{
enum string expand = mixin(toConcatenatedForm(m, args));
}
unittest
{
enum string s = expand!("$1", "abc");
writeln(s);
writeln(expand!("$1", s));
}
void main(){}
The code above causes an ICE:
Assertion failed: (v->ctfeAdrOnStack >= 0 && v->ctfeAdrOnStack < stackPointer()), function setValue, file interpret.c, line 100.
Replacing the first line in the unittest with
static immutable string s = expand!("$1", "abc");
makes the code work.
Comment #1 by bearophile_hugs — 2012-01-01T18:15:19Z
Reduced a bit:
int foo(int[] x...) {
return 0;
}
template bar(y...) {
enum int bar = foo(y);
}
enum int z = 1;
enum int w = bar!(z);
void main() {}
Comment #2 by erkle64 — 2012-01-25T10:00:46Z
Weird, it can be fixed by changing z to a const:
int foo(int[] x...) {
return 0;
}
template bar(y...) {
enum int bar = foo(y);
}
const int z = 1;
enum int w = bar!(z);
void main() {}
I'm unable to upgrade to 2.057 because of this bug, it works fine in 2.056.
Comment #3 by github-bugzilla — 2012-01-27T00:51:34Z