www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1310] New: alias opCall vs struct literal

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1310

           Summary: alias opCall vs struct literal
           Product: D
           Version: 1.017
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: lutger.blijdestijn gmail.com


When a struct has opCall through an alias, it is not recognized if the aliased
symbol is a delegate (not as in a member function). Whether this construct is
legal or not, the current behaviour is inconsistent. The following compiles
without error but does not do what one expects.

This applies to dmd 1.014-dmd 1.018 and probably the 2.x branch too. 

struct A
{
    int delegate() foo;
    alias foo opCall; // not seen, see below
}

struct B
{
    int foo() { return 0; }
    alias foo opCall; // ok
}

void main()
{
    A a;
    B b;
    auto resultA = a();
    pragma(msg, typeof(resultA).stringof); // prints 'A', struct initializer
    auto resultB = b();
    pragma(msg, typeof(resultB).stringof); // prints 'int', recognizes opCall
}


-- 
Jul 02 2007
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1310


thomas-dloop kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
         OS/Version|Windows                     |All
           Platform|PC                          |All




------- Comment #1 from thomas-dloop kuehne.cn  2007-07-23 14:55 -------
The same behaviour is caused by:

# struct A {
#     int opCall;
# }

As far as I can see the code behaves as documented - opCall expects a function 
not a delegate or function pointer - however issuing at least a warning if -w 
is used would be sensible. Adding delegate/function pointer support for op* 
member functions might be interesting nevertheless.


-- 
Jul 23 2007