Fix ICE in infer when giving error suggestions

This fixes an ICE and closes issue #17758