7154 – [CTFE] failing downcast causes error

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7154 - [CTFE] failing downcast causes error
Summary: [CTFE] failing downcast causes error
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
Reported: 2011年12月22日 07:45 UTC by Elvis Maehren
Modified: 2011年12月26日 16:03 UTC (History)
1 user (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Elvis Maehren 2011年12月22日 07:45:40 UTC
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
}
---


AltStyle によって変換されたページ (->オリジナル) /