Fixes #101859. If we have at least 2 ranges, we have to try to merge the last and first ones to handle the wrap range.