So can the gun. Pistolwhipping, anyone? Plus, prior to the invention of the bayonet, muskets and rifles were sometimes used as blunt weapons in close quarters combat due to their size and weight. They sometimes still are - a bayonet can take a few seconds to equip which in battle you may not always have.
Besides, a sword on its own does nothing, either. It is an inanimate object. Without a wielder, a sword is nigh harmless. All in all, this sword vs. gun analogy is a bit flawed, tbh.