www.digitalmars.com         C & C++   DMDScript  

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

reply d-bugmail puremagic.com writes:

           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
next sibling parent d-bugmail puremagic.com writes:

thomas-dloop kuehne.cn changed:

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

The same behaviour is caused by:

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
prev sibling parent d-bugmail puremagic.com writes:

Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |verylonglogin.reg gmail.com

13:30:40 MSD ---
By the way, latest dmd v2.060 correctly (as documented) complains:
Error: struct A does not overload ()

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 09 2012