The code had a problem that got fixed in !2838 (merged) . It would be good to add a unit test for it.