I agree that this is a bug in the LaTeX kernel. The \If... constructs should never rely on propery nested TeX conditionals.