Why it doesn't compile in D 2.0?

Don nospam at nospam.com
Wed Jan 20 04:55:48 PST 2010


aarti_pl wrote:
> W dniu 2010-01-17 19:38, Don pisze:
>> aarti_pl wrote:
>>>
>>> class Test {
>>> string t1 = "test"; //Ok!
>>> char[] t2 = "test".dup; //Compile error
>>> }
>>>
>>> void main(char[][] args) {
>>> }
>>>
>>> Error:
>>> hello.d(3): Error: cannot evaluate _adDupT((&
>>> D12TypeInfo_Aya6__initZ),"test") at compile time
>>> hello.d(3): Error: cannot evaluate _adDupT((&
>>> D12TypeInfo_Aya6__initZ),"test") at compile time
>>>
>>> Is there workaround?
>>>
>>> BR
>>> Marcin Kuszczak
>>> (aarti_pl)
>>
>> Workaround: It works in dmd2, svn 337 and later <g>.
> 
> Wow. I even could not report it as a bug. That is really fast bug fixing 
> :-)

It wasn't specifically a fix of this bug. Some long-standing CTFE 
limitations were fixed, which make lots of things start working.

> Could you please explain what has initialization of variables to do with 
> CTFE? As far as I understand it should be done on runtime... So why is 
> there compile time execution involved?

It shouldn't be happening. There's a bug somewhere.

> And other questions. Would it be possible to initialize more complex 
> types with better CTFE? I see it as quite major issue when I can not 
> write in class definition or in global scope:
> 
> auto serializer = new Serializer!(TextArchive)();

If you can't do that now, that's a serious bug.
But classes will eventually work in CTFE.


More information about the Digitalmars-d-learn mailing list