https://issues.dlang.org/show_bug.cgi?id=22384
Issue ID: 22384
Summary: castSwitch confused by noreturn handlers
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: [email protected]
Reporter: [email protected]
castSwitch allows handlers that neither return a value nor throw an exception -
as long as no other handler returns a value. This breaks when passing noreturn
handlers, causing castSwitch to throw an exception for the void handlers that
don't trow an exception and hence being inferred as noreturn.
Example
void main()
{ static void objectSkip(Object) {}
static void defaultSkip() {}
static noreturn objectError(Object) { assert(false); }
static noreturn defaultError() { assert(false); }
{
alias test = castSwitch!(objectSkip, defaultError);
static assert(is(ReturnType!test == void)); // fails,
noreturn
}{
alias test = castSwitch!(objectError, defaultSkip);
static assert(is(ReturnType!test == void)); // fails,
noreturn
}{
alias test = castSwitch!(objectError, defaultError);
static assert(is(ReturnType!test == noreturn)); // valid
}
}
--