Thread overview
[Issue 1723] New: __traits(getVirtualFunctions) on a non-function fails badly
Dec 10, 2007
d-bugmail
Feb 27, 2008
d-bugmail
Feb 27, 2008
d-bugmail
Mar 12, 2008
d-bugmail
Mar 12, 2008
Christopher Wright
May 11, 2008
d-bugmail
December 10, 2007
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.


-- 

February 27, 2008
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. ***


-- 

February 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.


-- 

March 12, 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.


-- 

March 12, 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.
May 11, 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


--