Problem with ReturnType

Neil Vice sardonicpresence at gmail.com
Wed Apr 2 18:06:39 PDT 2008


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:ft14od$22lv$1 at digitalmars.com...
> After an 1+ hours long bug hunt, I have reduced my code to the following 
> one.
> ReturnType below is a reduced version of std.traits.ReturnType:
>
> template ReturnType(T) {
>    static if (is(T R == return))
>        alias R ReturnType;
> }
>
> void bar(T)(T f) { return f(); }
>
> void main() {
>    alias ReturnType!( typeof( (int x){ return x; } ) ) TInt; //problem
>    bar((int n=1) { return 2; });
> }
>
> The output:
> test.d(6): Error: expected 1 arguments, not 0
> test.d(10): template instance test.bar!(int delegate(int x)) error 
> instantiating
>
> Is this a bug of DMD/Phobos (I am using 1.028)?
>
> Bye,
> bearophile

How bizarre... I just tried your code and it would appear that somehow the 
presence of the alias/ReturnType call causes the default parameter value in 
the subsequent line to be seemingly ignored...

Passing a parameter to the call to f() in bar, eliminating the alias line 
and removing the parameter from the delegate passed to bar all eliminate the 
error.

I don't see how this could be anything other than a very unusual compiler 
bug. Happy bug reporting =) 




More information about the Digitalmars-d-learn mailing list