Fix #2515 (manually merge PR #2516)