www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7760] New: Getting delegate address from class object requires unneeded cast


           Summary: Getting delegate address from class object requires
                    unneeded cast
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: k.hara.pg gmail.com

--- Comment #0 from Kenji Hara <k.hara.pg gmail.com> 2012-03-24 08:04:44 PDT ---
Following code doesn't work.
void main()
    class C1 { string var = "c1"; alias var this; }

    auto c = new C1();
    string delegate() dg = &o.toString;
    // Error: e2ir: cannot cast c.var of type string to type object.Object

    Object o = c;
    string delegate() dg = &o.toString;


This is CastExp::semantic issue.

In DelegateExp::semantic, &c.toString is translated to
Next in castExp::semantic, cast(Object)c is translated to cast(Object)(c.var),
because class C1 has an alias this declaration.
Of cause, this is bad cast, but semantic analysis doesn't check whether it is
invalid cast or not. Then this expression is rejected and raise an error in
glue layer.

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