digitalmars.D.learn - Problem with ReturnType
- bearophile (17/17) Apr 02 2008 After an 1+ hours long bug hunt, I have reduced my code to the following...
- Neil Vice (10/29) Apr 02 2008 How bizarre... I just tried your code and it would appear that somehow t...
- janderson (2/25) Apr 04 2008
- bearophile (6/7) Apr 04 2008 I know, that code isn't the minimal yet, but even if you replace bar wit...
- janderson (3/14) Apr 04 2008 My bad. It does look like a compiler deficiency.
- Kirk McDonald (7/30) Apr 04 2008 Delegates can't have default arguments.
- bearophile (4/5) Apr 04 2008 I don't understand much. I think what you say isn't enough to justify th...
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
Apr 02 2008
"bearophile" <bearophileHUGS lycos.com> wrote in message news:ft14od$22lv$1 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, bearophileHow 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 =)
Apr 02 2008
bearophile wrote: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(); }There is no return type. alias Return is returning an int.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
Apr 04 2008
janderson:There is no return type. alias Return is returning an int.I know, that code isn't the minimal yet, but even if you replace bar with: void bar(T)(T f) { f(); } The situation doesn't change. Bye, bearophile
Apr 04 2008
bearophile wrote:janderson:My bad. It does look like a compiler deficiency. -JoelThere is no return type. alias Return is returning an int.I know, that code isn't the minimal yet, but even if you replace bar with: void bar(T)(T f) { f(); } The situation doesn't change. Bye, bearophile
Apr 04 2008
bearophile wrote: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, bearophileDelegates can't have default arguments. -- Kirk McDonald http://kirkmcdonald.blogspot.com Pyd: Connecting D and Python http://pyd.dsource.org
Apr 04 2008
Kirk McDonald:Delegates can't have default arguments.I don't understand much. I think what you say isn't enough to justify that error, you may comment out some of those lines of code to see the results. But maybe I just don't understand you. Bye and sorry, bearophile
Apr 04 2008