Skip to content

Commit

Permalink
Fix Issue 18166 - std.array.replace should be usable in @safe for dst…
Browse files Browse the repository at this point in the history
…rings
  • Loading branch information
JackStouffer committed Mar 12, 2018
1 parent 9194efb commit 13cf12d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion std/array.d
Expand Up @@ -2268,7 +2268,14 @@ if (isInputRange!Range &&
copy(stuff, retval[from .. from + stuff.length]);

retval[from + stuff.length .. $] = subject[to .. $];
return cast(T[]) retval;
static if (is(T == const) || is(T == immutable))
{
return () @trusted { return cast(T[]) retval; } ();
}
else
{
return cast(T[]) retval;
}
}
else
{
Expand Down Expand Up @@ -2362,6 +2369,13 @@ if (isInputRange!Range &&
assert(replace(d, 5, 10, "⁴³²¹⁰"d) == "⁰¹²³⁴⁴³²¹⁰"d);
}

// Issue 18166
@safe pure unittest
{
auto str = replace("aaaaa"d, 1, 4, "***"d);
assert(str == "a***a");
}

/++
Replaces elements from `array` with indices ranging from `from`
(inclusive) to `to` (exclusive) with the range `stuff`. Expands or
Expand Down

0 comments on commit 13cf12d

Please sign in to comment.