I wanted a semantic construct to specifically denote unreachable control-flow branches, so here it is. Prints out an error with file and line number upon being erroneously reached.
This is useful, a project I work on has a utility function which is similar but relies on a backtrace to actually get locations, so something like this already has a leg up.
A PPX over a utility function might be useful in a second way as well, which is I’ve always wanted the “unreachable” lines to be excluded from ppx_bisect’s coverage reports. I think doing something with a staged preprocessor could mean I finally get that…
The standard way of denoting unreachable cases is assert false
, which bisect_ppx should already be excluding: bisect_ppx/src/ppx/instrument.ml at dc29402f2f8b6246150b18ac2e7e1d48e578a106 · aantron/bisect_ppx · GitHub.
Ah, I didn’t realize. I think we all have had cases where an “unreachable” case actually was reached due to a bug somewhere else, which is why something like the ppx here is more useful than simply asserting false. In my code I also include a link to the bug tracker in these messages.