Bug 7154 – [CTFE] failing downcast causes error

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2011-12-22T07:45:00Z
Last change time
2011-12-26T16:03:28Z
Assigned to
nobody
Creator
maehlvis

Comments

Comment #0 by maehlvis — 2011-12-22T07:45:40Z
At runtime, a failing downcast evaluates to null. At compile time, it gives an error: "Error: cannot reinterpret class from C to test.B at compile time" It should just evaluate to null, too. --- class A {} class B : A {} class C : A {} bool test(T)() { A a = new T; return (cast(B) a) !is null; } void main() { assert(test!B()); // ok assert(!test!C()); // ok static assert(test!B()); // ok static assert(!test!C()); // error } ---
Comment #1 by clugdbug — 2011-12-26T16:03:28Z