www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1723] New: __traits(getVirtualFunctions) on a non-function fails badly

reply d-bugmail puremagic.com writes:
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1723






*** Bug 1872 has been marked as a duplicate of this bug. ***


-- 
Feb 27 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1723






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
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1723






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
parent Christopher Wright <dhasenan gmail.com> writes:
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
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1723


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed dmd 2.013


-- 
May 11 2008