[Issue 14298] New: std.typecons.Proxy incorrectly defines opCast operator, that breaks casting to supertype.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Mar 16 16:54:25 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14298
Issue ID: 14298
Summary: std.typecons.Proxy incorrectly defines opCast
operator, that breaks casting to supertype.
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: Phobos
Assignee: nobody at puremagic.com
Reporter: luk.wrzosek at gmail.com
//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; }
--
More information about the Digitalmars-d-bugs
mailing list