Fix bug in ranges_expand, whereby masks are not passed through the recursion.