From c544c9e7e3f3384c70b3d4309ae579718a56beb3 Mon Sep 17 00:00:00 2001 From: "H. S. Teoh" Date: Wed, 9 Aug 2017 17:02:40 -0700 Subject: [PATCH 1/2] Don't use alias this in chunks implementation. --- std/range/package.d | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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() From 9091b16f5ce52e1d26128770b4a1e7866ee1cd0f Mon Sep 17 00:00:00 2001 From: "H. S. Teoh" Date: Thu, 10 Aug 2017 13:10:35 -0700 Subject: [PATCH 2/2] Add unittest. Needs to be a standalone module because the problem does not show up within std.range itself. --- posix.mak | 2 +- std/internal/test/range.d | 25 +++++++++++++++++++++++++ win32.mak | 3 ++- win64.mak | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 std/internal/test/range.d 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/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