Inflation does hurt the underlying companies, and thus stocks are not immune.
Except in cases with extremely high inflation most contracts are not inflation adjusted. By the time a company is paid the merchandise sold is worth significantly more in fiat terms. In high inflation an entity is loathe to trade assets for dollars and so the economy will slow.