From b42cd6e8fc3ec669d67b8b4f2fcf92cb5d0a08d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Kj=C3=A6r=C3=A5s?= Date: Mon, 15 Jun 2020 09:02:40 +0200 Subject: [PATCH] Fix issue 20928 --- std/algorithm/iteration.d | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/std/algorithm/iteration.d b/std/algorithm/iteration.d index 4cbf903eec2..4ffd0f3532c 100644 --- a/std/algorithm/iteration.d +++ b/std/algorithm/iteration.d @@ -630,7 +630,7 @@ private struct MapResult(alias fun, Range) static if (isRandomAccessRange!R) { - static if (is(typeof(_input[ulong.max]))) + static if (is(typeof(Range.init[ulong.max]))) private alias opIndex_t = ulong; else private alias opIndex_t = uint; @@ -870,6 +870,23 @@ private struct MapResult(alias fun, Range) assert(m.front == immutable(S)(null)); } +// Issue 20928 +@safe unittest +{ + struct Always3 + { + enum empty = false; + auto save() { return this; } + long front() { return 3; } + void popFront() {} + long opIndex(ulong i) { return 3; } + long opIndex(ulong i) immutable { return 3; }; + } + + import std.algorithm.iteration : map; + Always3.init.map!(e => e)[ulong.max]; +} + // each /** Eagerly iterates over `r` and calls `fun` over _each element.