digitalmars.D.learn - template interface and delegates
- anonymous (26/26) Mar 31 2014 Hi,
- Justin Whear (53/85) Mar 31 2014 Looks like a bug. Here's a cleaned-up test case:
- Steven Schveighoffer (25/51) Mar 31 2014 This is definitely a bug.
- anonymous (2/2) Mar 31 2014 Ok, thought i did something wrong or got some wrong idea how it
- anonymous (3/5) Apr 01 2014 Is this bug allready reported? or can somebody who has a deeper
- Steven Schveighoffer (4/6) Apr 01 2014 I don't know. I think you should report it. If it's already reported,
- Kenji Hara (5/12) Apr 02 2014 I filed it.
Hi, I'm new to D and played a bit with templates and delegates. Now i discovered some behaviore that i don't understand. Can somebody explain me why i get two different outputs? import std.stdio; interface A(T){ bool GetBool(); T getT(); } class C:A!(double){ override bool GetBool(){ return false; } override double getT(){ return 1; } } void mwriteln(T)( A!T delegate() dg){ writeln(dg().getT()); } void main() { auto c = new C(); writeln(c.getT()); mwriteln!double({return new C();}); }
Mar 31 2014
On Mon, 31 Mar 2014 18:58:30 +0000, anonymous wrote:Hi, I'm new to D and played a bit with templates and delegates. Now i discovered some behaviore that i don't understand. Can somebody explain me why i get two different outputs? import std.stdio; interface A(T){ bool GetBool(); T getT(); } class C:A!(double){ override bool GetBool(){ return false; } override double getT(){ return 1; } } void mwriteln(T)( A!T delegate() dg){ writeln(dg().getT()); } void main() { auto c = new C(); writeln(c.getT()); mwriteln!double({return new C();}); }Looks like a bug. Here's a cleaned-up test case: ----------------------------------------------------------- interface A(T) { T getT(); } class C : A!double { double getT(){ return 1; } } void mwriteln(T)(A!T delegate() dg) { import std.stdio; auto a = dg(); writeln("Checkpoint 1"); assert(a !is null); writeln(a); writeln("Checkpoint 2"); } void main() { import std.traits; static assert(isImplicitlyConvertible!(C, A!double)); mwriteln!double({return new C();}); } ----------------------------------------------------------- Backtrace: ----------------------------------------------------------- Program received signal SIGSEGV, Segmentation fault. std.format.__T11formatValueTS3std5stdio4File17LockingTextWriterTC4test8__T1ATdZ1ATaZ.formatValue () () std.format.__T13formatGenericTS3std5stdio4File17LockingTextWriterTC4test8__T1ATdZ1ATaZ.formatGeneric () () std.format.__T14formattedWriteTS3std5stdio4File17LockingTextWriterTaTC4test8__T1ATdZ1AZ.formattedWrite () () std.stdio.File.__T5writeTC4test8__T1ATdZ1ATaZ.write() () () () -----------------------------------------------------------
Mar 31 2014
On Mon, 31 Mar 2014 14:58:30 -0400, anonymous <non trash-mail.com> wrote:Hi, I'm new to D and played a bit with templates and delegates. Now i discovered some behaviore that i don't understand. Can somebody explain me why i get two different outputs? import std.stdio; interface A(T){ bool GetBool(); T getT(); } class C:A!(double){ override bool GetBool(){ return false; } override double getT(){ return 1; } } void mwriteln(T)( A!T delegate() dg){ writeln(dg().getT()); } void main() { auto c = new C(); writeln(c.getT()); mwriteln!double({return new C();}); }This is definitely a bug. Reduced case: import std.stdio; interface A{ void foo(); } class C:A{ override void foo(){ writeln("here"); } } void x( A delegate() dg){ dg().foo(); } void main() { A c = new C; c.foo(); // prints "here" x({A a = new C; return a;}); // prints "here" x({return new C;}); // does not print } This is really an issue with delegate return type inferrence not working properly. -Steve
Mar 31 2014
Ok, thought i did something wrong or got some wrong idea how it should work.
Mar 31 2014
Is this bug allready reported? or can somebody who has a deeper insight to this report it? On Tuesday, 1 April 2014 at 05:51:46 UTC, anonymous wrote:Ok, thought i did something wrong or got some wrong idea how it should work.
Apr 01 2014
On Tue, 01 Apr 2014 15:47:42 -0400, anonymous <non trash-mail.com> wrote:Is this bug allready reported? or can somebody who has a deeper insight to this report it?I don't know. I think you should report it. If it's already reported, someone will close it as a "duplicate" -Steve
Apr 01 2014
On Tuesday, 1 April 2014 at 19:55:05 UTC, Steven Schveighoffer wrote:On Tue, 01 Apr 2014 15:47:42 -0400, anonymous <non trash-mail.com> wrote:I filed it. https://d.puremagic.com/issues/show_bug.cgi?id=12508 Kenji HaraIs this bug allready reported? or can somebody who has a deeper insight to this report it?I don't know. I think you should report it. If it's already reported, someone will close it as a "duplicate" -Steve
Apr 02 2014