Fix logic in dependency checking

This bit crys out for some testing: this should never have happened
and is not tested.