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

--- Comment #0 from Kenji Hara <> 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:
------- You are receiving this mail because: -------

Reply via email to