It is not a bug of the validator, since the validator can't understand
(semantically) the meaning of the program, it is an undecidable question.
Again, you should state the doctype only once in your document, for
example you can write a function that writes the doctype and then you call
it from the two branches that need to use it.