digitalmars.D.bugs - [Issue 2740] New: Template Mixins do not work as advertised
- d-bugmail puremagic.com (45/45) Mar 17 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (5/5) Mar 17 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (34/34) Sep 08 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (28/28) Sep 08 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (19/19) Dec 03 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (6/6) Dec 03 2010 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (15/28) Feb 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (11/11) Jul 09 2011 http://d.puremagic.com/issues/show_bug.cgi?id=2740
- d-bugmail puremagic.com (13/13) Oct 13 2011 http://d.puremagic.com/issues/show_bug.cgi?id=2740
http://d.puremagic.com/issues/show_bug.cgi?id=2740 Summary: Template Mixins do not work as advertised Product: D Version: unspecified Platform: PC OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: andrew.livesay gmail.com // As I understand TFM, all three calls to go() should be printing 'false'. import std.stdio; interface IFooable { bool foo(); } template TFoo() { bool foo() { return true; } } class Foo : IFooable { mixin TFoo; bool foo() { return false; } } class _Foo : IFooable { mixin TFoo; } class Foo2 : _Foo { bool foo() { return false; } } class Foo3 : IFooable { bool foo() { return false; } } void go(IFooable p) { writefln(p.foo); } void main() { Foo p = new Foo(); Foo2 p2 = new Foo2(); Foo3 p3 = new Foo3(); go(p); // output is "true" <------- Why isn't this false? go(p2); // output is "false" go(p3); // output is "false" } --
Mar 17 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2740 Issue appears to be dependent on the order the mixin is imported. If you redefine foo() before "mixin TFoo;", it works as expected. --
Mar 17 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2740 David Simcha <dsimcha yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dsimcha yahoo.com Severity|normal |critical This seems to happen iff the class is called from its interface handle: import std.stdio; interface IFooable { bool foo(); } mixin template TFoo() { override bool foo() { return true; } } class Foo : IFooable { mixin TFoo; override bool foo() { return false; } } void go(IFooable p) { writeln(p.foo); } void main() { Foo p = new Foo(); go(p); // true writeln(p.foo); // false IFooable i = p; writeln(i.foo); // true } Marking as critical because this is an extremely subtle wrong-code bug that can lead to some pretty frustrating debugging. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2740 Oh yeah, doesn't happen for abstract classes either. Looks like only the interface vtbl info is wrong. import std.stdio; abstract class IFooable { abstract bool foo(); } mixin template TFoo() { override bool foo() { return true; } } class Foo : IFooable { mixin TFoo; override bool foo() { return false; } } void go(IFooable p) { writeln(p.foo); } void main() { Foo p = new Foo(); go(p); // false writeln(p.foo); // false IFooable i = p; writeln(i.foo); // false } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2740 Bruno Medeiros <bdom.pub+deebugz gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bdom.pub+deebugz gmail.com 06:33:18 PST --- Hum, I suspect the code above should not even compile. Instantiating the mixin "is analogous to cutting and pasting the body of the template into the location of the mixin." http://www.digitalmars.com/d/2.0/template-mixin.html Thus it should be the same as: class Foo : IFooable { bool foo() { return false; } bool foo() { return false; } } which should be a semantic error, I think. See http://d.puremagic.com/issues/show_bug.cgi?id=5312 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 03 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2740 11:57:37 PST --- The right code can't be generated for such input. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 03 2010
http://d.puremagic.com/issues/show_bug.cgi?id=2740 akb825 gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |akb825 gmail.comHum, I suspect the code above should not even compile. Instantiating the mixin "is analogous to cutting and pasting the body of the template into the location of the mixin." http://www.digitalmars.com/d/2.0/template-mixin.html Thus it should be the same as: class Foo : IFooable { bool foo() { return false; } bool foo() { return false; } } which should be a semantic error, I think. See http://d.puremagic.com/issues/show_bug.cgi?id=5312From http://www.digitalmars.com/d/2.0/template-mixin.html: "The declarations in a mixin are ‘imported’ into the surrounding scope. If the name of a declaration in a mixin is the same as a declaration in the surrounding scope, the surrounding declaration overrides the mixin one." In other words, declarations in the current scope always hide declarations in the mixin. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 19 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2740 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch CC| |k.hara.pg gmail.com https://github.com/D-Programming-Language/dmd/pull/223 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 09 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2740 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED 19:40:50 PDT --- https://github.com/D-Programming-Language/dmd/commit/4081225e4407ca08d6c8f9a390e1bb6def057c29 https://github.com/D-Programming-Language/dmd/commit/73e600b38ec0fdcadd3855db4b0ccac53a451da0 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 13 2011