www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16951] New: trying to call opCall with alias opCall this,

https://issues.dlang.org/show_bug.cgi?id=16951

          Issue ID: 16951
           Summary: trying to call opCall with alias opCall this, without
                    parentesis fails to compile, when used as a single
                    statement
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: var.spool.mail700 gmail.com

struct A
{
    alias opCall this;
    int opCall() { return 0; }
}

void main()
{
    A a;
    // a; // Error: var has no effect in expression (a)

    // some working examples but with some issues
    auto a1 = a;  // calls copy constructor
    int a2 = a;   // calls opCall
    a.writeln;    // toString
    a.someIntFun; // opCall
}

those issues can be partialy solved by adding  property to opCall

struct A
{
    alias opCall this;
     property int opCall() { return 0; }
}

void main()
{
    A a;
    // a; // still Error: var has no effect in expression (a)

    auto a1 = a;  // copy constructor
    int a2 = a;   // opCall
    a.writeln;    // opCall
    a.someIntFun; // opCall
}

dont know if its a bug or not but would be nice if the commented line would
compile.

--
Dec 06 2016