From 289149a2f1e582d8fcbe74dbead47c1a01f8201c Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Wed, 25 Sep 2019 07:50:24 +0000 Subject: [PATCH] Fix Issue 20241 - BitArray.bitsSet ignores length --- std/bitmanip.d | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/std/bitmanip.d b/std/bitmanip.d index 5e3e15d80..adc3defc0 100644 --- a/std/bitmanip.d +++ b/std/bitmanip.d @@ -2585,12 +2585,16 @@ public: @property auto bitsSet() const nothrow { import std.algorithm.iteration : filter, map, joiner; - import std.range : iota; + import std.range : iota, chain; - return iota(dim). - filter!(i => _ptr[i])(). - map!(i => BitsSet!size_t(_ptr[i], i * bitsPerSizeT))(). - joiner(); + return chain( + iota(fullWords) + .filter!(i => _ptr[i])() + .map!(i => BitsSet!size_t(_ptr[i], i * bitsPerSizeT))() + .joiner(), + iota(fullWords * bitsPerSizeT, _len) + .filter!(i => this[i])() + ); } /// @@ -2630,6 +2634,16 @@ public: assert(b.bitsSet.equal(iota(wordBits * 2))); } + // Issue 20241 + @system unittest + { + BitArray ba; + ba.length = 2; + ba[1] = 1; + ba.length = 1; + assert(ba.bitsSet.empty); + } + private void formatBitString(Writer)(auto ref Writer sink) const { if (!length)