Bug 7760 – Getting delegate address from class object requires unneeded cast

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-24T08:04:00Z
Last change time
2013-11-28T19:53:00Z
Keywords
rejects-valid
Assigned to
nobody
Creator
k.hara.pg
Depends on
7472

Comments

Comment #0 by k.hara.pg — 2012-03-24T08:04:44Z
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 ***