Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
September 20, 2012 CTFE calling a template: Error: expression ... is not a valid template value argument | ||||
---|---|---|---|---|
| ||||
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 |
September 20, 2012 Re: CTFE calling a template: Error: expression ... is not a valid template value argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jens Mueller | I'm guessing the problem is that it's trying to call CTFE on a function whose full AST isn't known yet (because it requires the CTFE param, which requires the function etc.) This could work in theory, but I'm guessing the implementation is tricky. |
September 20, 2012 Re: CTFE calling a template: Error: expression ... is not a valid template value argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jens Mueller | 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 |
September 21, 2012 Re: CTFE calling a template: Error: expression ... is not a valid template value argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Le 21/09/2012 01:13, Timon Gehr a écrit :
> You could post an enhancement request to allow interpretation of
> incompletely-analyzed functions, if you think it is of any use.
>
I predict tricky implementation.
|
September 21, 2012 Re: CTFE calling a template: Error: expression ... is not a valid template value argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Timon Gehr wrote: > 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. That is true. I will file such a diagnostics bug with low priority. > You could post an enhancement request to allow interpretation of incompletely-analyzed functions, if you think it is of any use. I think it is. What do you think? Jens |
September 21, 2012 Re: CTFE calling a template: Error: expression ... is not a valid template value argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 09/21/2012 10:29 AM, deadalnix wrote:
> Le 21/09/2012 01:13, Timon Gehr a écrit :
>> You could post an enhancement request to allow interpretation of
>> incompletely-analyzed functions, if you think it is of any use.
>>
>
> I predict tricky implementation.
This depends on the existing code base. It is not inherently tricky.
|
September 21, 2012 Re: CTFE calling a template: Error: expression ... is not a valid template value argument | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jens Mueller | On 09/21/2012 12:23 PM, Jens Mueller wrote:
> Timon Gehr wrote:
>...
>> 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.
>
> That is true. I will file such a diagnostics bug with low priority.
>
>> You could post an enhancement request to allow interpretation of
>> incompletely-analyzed functions, if you think it is of any use.
>
> I think it is.
> What do you think?
>
I think if it has an obvious interpretation (and in this case, it even
has an obvious analysis strategy) it should compile.
|
Copyright © 1999-2021 by the D Language Foundation