digitalmars.D.bugs - [Issue 1723] New: __traits(getVirtualFunctions) on a non-function fails badly
- d-bugmail puremagic.com (36/36) Dec 10 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1723
- d-bugmail puremagic.com (4/4) Feb 27 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1723
- d-bugmail puremagic.com (9/9) Feb 27 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1723
- d-bugmail puremagic.com (5/5) Mar 11 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1723
- Christopher Wright (3/3) Mar 12 2008 Then what should happen if I call it on a final function? The same thing...
- d-bugmail puremagic.com (9/9) May 11 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1723
http://d.puremagic.com/issues/show_bug.cgi?id=1723 Summary: __traits(getVirtualFunctions) on a non-function fails badly Product: D Version: 2.008 Platform: PC OS/Version: Linux Status: NEW Keywords: diagnostic, rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: dhasenan gmail.com --- class Foo { int i; void f() {} } void main () { // Succeeds: foreach (m; __traits(getVirtualFunctions, Foo, "f")) {} // Fails: foreach (m; __traits(getVirtualFunctions, Foo, "i")) {} } --- The error message is: virtualfunctions_notfunction.d(9): Error: 'this' is only allowed in non-static member functions, not main virtualfunctions_notfunction.d(9): Error: this for i needs to be type Foo not type int I also get this when trying to access the .length property of the resulting tuple. If there are no virtual methods with the given name, an empty tuple should be returned. At the very least, it should have a decent error message. --
Dec 10 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1723 ------- Comment #1 from dhasenan gmail.com 2008-02-27 07:28 ------- *** Bug 1872 has been marked as a duplicate of this bug. *** --
Feb 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1723 ------- Comment #2 from dhasenan gmail.com 2008-02-27 07:35 ------- The obvious workaround: static if (__traits(compiles, (__traits(getVirtualFunctions, T, name)))) { foreach (i, method; __traits(getVirtualFunctions, T, name)) {} } It's an ugly way to work around compiler bugs, though. --
Feb 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1723 ------- Comment #3 from bugzilla digitalmars.com 2008-03-12 00:05 ------- Since "i" is not a virtual function, the error message, while unclear, is justified as the code is not valid. I'll improve the error message. --
Mar 11 2008
Then what should happen if I call it on a final function? The same thing? At any rate, I'm left with the same ugly workaround. If you're not going to make that workaround unnecessary, please add it to std.traits.
Mar 12 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1723 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #5 from bugzilla digitalmars.com 2008-05-11 04:13 ------- Fixed dmd 2.013 --
May 11 2008