Sharp version of the Goldberg–Sachs theorem