On 09/20/2012 11:22 PM, Jens Mueller wrote:
Hi,

I do not understand the following error message given the code:

string foo(string f)
{
     if (f == "somestring")
     {
         return "got somestring";
     }
     return bar!(foo("somestring"));
}

template bar(string s)
{
     enum bar = s;
}

I'll with dmd v2.060 get:
test.d(7):        called from here: foo("somestring")
test.d(7):        called from here: foo("somestring")
test.d(7):        called from here: foo("somestring")
test.d(7): Error: expression foo("somestring") is not a valid template value 
argument
test.d(12):        called from here: foo("somestring")
test.d(12):        called from here: foo("somestring")
test.d(7): Error: template instance test.bar!(foo("somestring")) error 
instantiating

In line 7 I call the template bar. But I call with the string that is
returned by the CTFE of foo("somestring") which should return "got
somestring" but instead it seems that an expression is passed. How do I
force the evaluation foo("somestring")?
I haven't found a bug on this.

Jens


You can file a diagnostics-bug.

The issue is that CTFE can only interpret functions that are fully
analyzed and therefore the analysis of foo depends circularly on
itself. The compiler should spit out an error that indicates the
issue.

You could post an enhancement request to allow interpretation of
incompletely-analyzed functions, if you think it is of any use.

http://d.puremagic.com/issues

Reply via email to