Bug 14298 – std.typecons.Proxy incorrectly defines opCast operator, that breaks casting to supertype.
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-16T23:54:00Z
Last change time
2015-03-18T14:12:48Z
Assigned to
nobody
Creator
luk.wrzosek
Comments
Comment #0 by luk.wrzosek — 2015-03-16T23:54:25Z
//test case
import std.typecons;
class IA {}
class IB {}
class C : IB {
IA a;
mixin Proxy!a;
public this() {
a = new IA;
}
}
void main() {
C c = new C;
assert(c !is null);
IA a = cast(IA)c;
assert(a !is null);
IB b_ok = c;
assert(b_ok !is null); //implicit cast works
IB b_not_ok = cast(IB)c;
assert(b_not_ok !is null); //assert fails on explicit cast.
}
//Proxy template always casts to Proxy'ied type:
auto ref opCast(T, this X)() { return cast(T)a; }
Comment #1 by acehreli — 2015-03-18T14:12:48Z
Bug 5747 is related as well.
*** This issue has been marked as a duplicate of issue 9249 ***