Thread overview
Properties as template value parameters
Nov 28, 2005
Don Clugston
Nov 28, 2005
John C
Nov 28, 2005
Don Clugston
Dec 04, 2005
Thomas Kuehne
November 28, 2005
Seems to be an order-of-evaluation bug.
Fails to compile on DMD 0.140, Windows.

--------------
template cat(int n)
{
  const int dog = n;
}

const char [] bird = "canary";

const int sheep = cat!(bird.length).dog;

int main() { return 0; }
--------------
bug.d(9): no property 'length' for type 'char[]'
----------------
November 28, 2005
"Don Clugston" <dac@nospam.com.au> wrote in message news:dmef15$1nll$1@digitaldaemon.com...
> Seems to be an order-of-evaluation bug.
> Fails to compile on DMD 0.140, Windows.
>
> --------------
> template cat(int n)
> {
>   const int dog = n;
> }
>
> const char [] bird = "canary";
>
> const int sheep = cat!(bird.length).dog;

Works if you cast bird to char[]:

    const int sheep = cat!((cast(char[])bird).length).dog;

printf("%d\n", sheep); // prints '6'

>
> int main() { return 0; }
> --------------
> bug.d(9): no property 'length' for type 'char[]'
> ---------------- 


November 28, 2005
John C wrote:
> "Don Clugston" <dac@nospam.com.au> wrote in message news:dmef15$1nll$1@digitaldaemon.com...
> 
>>Seems to be an order-of-evaluation bug.
>>Fails to compile on DMD 0.140, Windows.
>>
>>--------------
>>template cat(int n)
>>{
>>  const int dog = n;
>>}
>>
>>const char [] bird = "canary";
>>
>>const int sheep = cat!(bird.length).dog;
> 
> 
> Works if you cast bird to char[]:
> 
>     const int sheep = cat!((cast(char[])bird).length).dog;
> 
> printf("%d\n", sheep); // prints '6'

Indeed, many minor changes will let it compile, eg

const int sheep = cat!((""~ bird).length).dog;

and

const int pig = bird.length;
const int sheep = cat!(pig).dog;

(I got sick of a,b,c in bug reports, from now on I'll use animals :-)
Of course insects would be more appropriate).


> 
> 
>>int main() { return 0; }
>>--------------
>>bug.d(9): no property 'length' for type 'char[]'
>>---------------- 
> 
> 
> 
December 04, 2005
Don Clugston schrieb am 2005-11-28:
> Seems to be an order-of-evaluation bug.
> Fails to compile on DMD 0.140, Windows.
>
> --------------
> template cat(int n)
> {
>    const int dog = n;
> }
>
> const char [] bird = "canary";
>
> const int sheep = cat!(bird.length).dog;
>
> int main() { return 0; }
> --------------
> bug.d(9): no property 'length' for type 'char[]'
> ----------------

Added to DStress as http://dstress.kuehne.cn/run/t/template_22.d http://dstress.kuehne.cn/run/t/template_class_15.d http://dstress.kuehne.cn/run/t/template_struct_06.d

Thomas