Skip to content

Commit f523a06

Browse files
committed
use static foreach for correct scope inference
1 parent d875674 commit f523a06

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

std/conv.d

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,23 @@ template to(T)
454454
assert(text(null) == "null");
455455
}
456456

457+
// Test `scope` inference of parameters of `text`
458+
@safe unittest
459+
{
460+
static struct S
461+
{
462+
int* x; // make S a type with pointers
463+
string toString() const scope
464+
{
465+
static int g = 0; // force toString to be impure for:
466+
g++; // https://issues.dlang.org/show_bug.cgi?id=20150
467+
return "S";
468+
}
469+
}
470+
scope S s;
471+
assert(text("a", s) == "aS");
472+
}
473+
457474
// Tests for issue 11390
458475
@safe pure /+nothrow+/ unittest
459476
{
@@ -4778,8 +4795,8 @@ private S textImpl(S, U...)(U args)
47784795
// assume that on average, parameters will have less
47794796
// than 20 elements
47804797
app.reserve(U.length * 20);
4781-
4782-
foreach (arg; args)
4798+
// Must be static foreach because of https://issues.dlang.org/show_bug.cgi?id=21209
4799+
static foreach (arg; args)
47834800
{
47844801
static if (
47854802
isSomeChar!(typeof(arg)) || isSomeString!(typeof(arg)) ||

std/range/package.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,8 @@ if (Ranges.length > 0 &&
932932
public:
933933
this(R input)
934934
{
935-
foreach (i, v; input)
935+
// Must be static foreach because of https://issues.dlang.org/show_bug.cgi?id=21209
936+
static foreach (i, v; input)
936937
{
937938
source[i] = v;
938939
}

0 commit comments

Comments
 (0)