This is in preparation for #2473. Also fixes a bug where switching on bools allows invalid case combinations.