diff --git a/posix.mak b/posix.mak index 321bdb1066b..122fe84bc39 100644 --- a/posix.mak +++ b/posix.mak @@ -227,7 +227,7 @@ EXTRA_MODULES_INTERNAL := $(addprefix std/, \ cstring digest/sha_SSSE3 \ $(addprefix math/, biguintcore biguintnoasm biguintx86 \ errorfunction gammafunction ) \ - scopebuffer test/dummyrange \ + scopebuffer test/dummyrange test/range \ $(addprefix unicode_, comp decomp grapheme norm tables) \ ) \ typetuple \ diff --git a/std/internal/test/range.d b/std/internal/test/range.d new file mode 100644 index 00000000000..6aa9676abf1 --- /dev/null +++ b/std/internal/test/range.d @@ -0,0 +1,25 @@ +/** +For testing only. +Contains tests related to member privacy that cannot be verified inside +std.range itself. +*/ +module std.internal.test.range; + +// Note: currently can't be @safe because RefCounted, which is used by chunks, +// isn't. +@system /*@safe*/ unittest +{ + import std.algorithm.comparison : equal; + import std.range : chunks; + + struct R + { + int state = 0; + @property bool empty() { return state >= 5; } + @property int front() { return state; } + void popFront() { state++; } + } + + auto r = R().chunks(3); + assert(r.equal!equal([[ 0, 1, 2 ], [ 3, 4 ]])); +} diff --git a/std/range/package.d b/std/range/package.d index f97356b2f6b..a54dfa7126f 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -7229,14 +7229,13 @@ if (isInputRange!Source) } private RefCounted!Impl impl; - alias impl this; private this(Source r, size_t chunkSize) { impl = RefCounted!Impl(r, r.empty ? 0 : chunkSize, chunkSize); } - @property bool empty() { return chunkSize == 0; } + @property bool empty() { return impl.chunkSize == 0; } @property Chunk front() return { return Chunk(impl); } void popFront() diff --git a/win32.mak b/win32.mak index 4c6821c42c2..5583adea472 100644 --- a/win32.mak +++ b/win32.mak @@ -276,7 +276,8 @@ SRC_STD_INTERNAL= \ std\internal\unicode_grapheme.d \ std\internal\unicode_norm.d \ std\internal\scopebuffer.d \ - std\internal\test\dummyrange.d + std\internal\test\dummyrange.d \ + std\internal\test\range.d SRC_STD_INTERNAL_DIGEST= \ std\internal\digest\sha_SSSE3.d diff --git a/win64.mak b/win64.mak index 6a7c552b4e0..c6751f8e54a 100644 --- a/win64.mak +++ b/win64.mak @@ -301,7 +301,8 @@ SRC_STD_INTERNAL= \ std\internal\unicode_grapheme.d \ std\internal\unicode_norm.d \ std\internal\scopebuffer.d \ - std\internal\test\dummyrange.d + std\internal\test\dummyrange.d \ + std\internal\test\range.d SRC_STD_INTERNAL_DIGEST= \ std\internal\digest\sha_SSSE3.d