[Issue 22384] New: castSwitch confused by noreturn handlers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 13 15:28:25 UTC 2021
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: nobody at puremagic.com
Reporter: moonlightsentinel at disroot.org
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
}
}
--
More information about the Digitalmars-d-bugs
mailing list