//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; }
Bug 5747 is related as well. *** This issue has been marked as a duplicate of issue 9249 ***