diff --git a/src/index_set.cpp b/src/index_set.cpp index b9b9525c..2c566e13 100644 --- a/src/index_set.cpp +++ b/src/index_set.cpp @@ -151,7 +151,7 @@ ChunkedRangeVector::iterator ChunkedRangeVector::erase(iterator pos) if (chunk.data.size() == 0) { pos.m_outer = m_data.erase(pos.m_outer); pos.m_end = m_data.end(); - pos.m_inner = pos.m_outer == m_data.end() ? nullptr : &pos.m_outer->data.back(); + pos.m_inner = pos.m_outer == m_data.end() ? nullptr : &pos.m_outer->data.front(); verify(); return pos; } diff --git a/tests/index_set.cpp b/tests/index_set.cpp index df5af2f1..ff62a05d 100644 --- a/tests/index_set.cpp +++ b/tests/index_set.cpp @@ -120,6 +120,17 @@ TEST_CASE("[index_set] add()") { set.add(i); REQUIRE_INDICES(set, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20); } + + SECTION("merges ranges even when they are in different chunks") { + realm::IndexSet set2; + for (int i = 0; i < 20; ++i) { + set.add(i * 2); + set2.add(i); + set2.add(i * 2); + } + set.add(set2); + REQUIRE(set.count() == 30); + } } TEST_CASE("[index_set] add_shifted()") {