Bug 8001 – Alias this takes ownership of explicit cast
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-29T07:41:00Z
Last change time
2013-11-09T10:52:42Z
Assigned to
nobody
Creator
Jesse.K.Phillips+D
Comments
Comment #0 by Jesse.K.Phillips+D — 2012-04-29T07:41:14Z
When attempting to downcast a class which uses alias this, the operation fails because the cast is applied to the item aliased.
I think the semantics should be to attempt an implicit cast (alias this), then a cast of the top class, afterwards the alias this item can be casted.
test.d(3): Error: e2ir: cannot cast a.val of type int to type test.B
void main () {
A a = new B();
B b = cast(B) a;
}
class A {
int val;
alias val this;
}
class B : A {}