Fix #5937 by removing dependence on which.