Final switch on default error template#1971
Conversation
|
Thanks for your pull request, @somzzz! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
This would be a breaking change. A better solution is to change @safe pure nothrow @nogc
void onSwitchError(string file = __FILE__, size_t line = __LINE__)
{
throw staticError!SwitchError(file, line, null);
}That way we keep compatibility with code that catches |
|
@ZombineDev I didn't notice Or after adding the With the current solution, an It shouldn't have been possible to mark code using |
3bd4e0b to
37a6eee
Compare
37a6eee to
007962f
Compare
|
Made |
PetarKirov
left a comment
There was a problem hiding this comment.
Thanks for the update, now everything LGTM.
| void __switch_errorT()(string file = __FILE__, size_t line = __LINE__) @trusted | ||
| { | ||
| // Consider making this a compile time check. | ||
| throw staticError!SwitchError(file, line, null); |
There was a problem hiding this comment.
Keep in mind, that we may need to add a if (__ctfe) assert (0, "informative message...") branch, as I'm not sure if staticError would work in CTFE.
I prefer to leave the PR as it is for now, and cross the bridges when we come to them.
| // Compiler lowers final switch default case to this (which is a runtime error) | ||
| void __switch_errorT()(string file = __FILE__, size_t line = __LINE__) @trusted | ||
| { | ||
| // Consider making this a compile time check. |
There was a problem hiding this comment.
We already have that compile time check for final switch and normal switch always requires a default branch.
I guess this runtime check is only used to verify that a value is not out-of-range, probably caused by an invalid cast. Ping @andralex
There was a problem hiding this comment.
@jpf91 take a look at https://dpaste.dzfl.pl/a33b4b74d774
There was a problem hiding this comment.
Thanks. I didn't know final switch also works on non-enumeral values.
Compiler lowers final switch default case to this (which is a runtime error).
Old implementation is in core/exception.d
Compiler changes: somzzz/dmd@d1bbf1e