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
}
Workaround:
----
Object o = c;
string delegate() dg = &o.toString;
====
This is CastExp::semantic issue.
In DelegateExp::semantic, &c.toString is translated to &(cast(Object)c).toString.
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.
Comment #1 by verylonglogin.reg — 2013-11-09T10:23:09Z
Original testcase works now. Resolved?
Comment #2 by k.hara.pg — 2013-11-28T19:53:00Z
(In reply to comment #1)
> Original testcase works now. Resolved?
Root cause was fixed in issue 10646.
*** This issue has been marked as a duplicate of issue 10646 ***