Port of Michel's fix for #3005 to `next`. Code review 2153.