Fixes accidental regression merging 9903ea1c11. Add test case for this kind of rebuilding.
9903ea1c11