Thread overview
[Issue 14925] replaceInPlace fail compilation
Aug 16, 2015
Florent GABRIEL
Aug 17, 2015
bb.temp@gmx.com
Mar 21, 2020
Basile-z
August 16, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

Florent GABRIEL <tsalm@free.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal

--
August 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

bb.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bb.temp@gmx.com
          Component|dmd                         |phobos

--
August 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Once again, the "specialized" nature of strings comes back to bite us.

The call matches the second overload (which just calls replace, and overwrites the original slice), because char[] is an input range, and char[] "isSomeString" and char[] has element type of dchar.

I think probably we need to verify in that branch of the if statement that T is immutable or const, or the element encoding type of the array is not T.

--
August 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

--- Comment #2 from Steven Schveighoffer <schveiguy@yahoo.com> ---
Hm... I was wrong I guess (sort of). The *second* overload is the one that should be chosen. This means that even though the replace could be done directly, it will reallocate.

This is because other pieces of the first overload cannot compile with narrow strings (namely, remove).

So I just added a constraint to the first to prevent it from being called on narrow strings, and updated the second to work for all cases that don't match the first.

I also found a bug where the first constraint would match 2 arrays where the second array wasn't identical, but the elements could be implicitly cast to the elements of the first.

For example:

auto a = [1L, 2, 3];
a.replaceInPlace(1, 2, [4,5,6]);

Which fails to compile on 2.068

--
August 17, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |All
                 OS|Linux                       |All

--- Comment #3 from Steven Schveighoffer <schveiguy@yahoo.com> ---
PR: https://github.com/D-Programming-Language/phobos/pull/3561

--
August 19, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

--- Comment #4 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/3f8b910e2c2834d2f87a543dc39692fe03a69c92
Fix issue 14925 -- merge overloads of replaceInPlace to avoid ambiguity
with template instantiation. Also, preclude narrow strings and other
invalid combinations (e.g. long[] and int[]) from being selected for
optimized path.

https://github.com/D-Programming-Language/phobos/commit/4d36627f363d9e23aae218578478a0c68da27278 Merge pull request #3561 from schveiguy/fix14925

Fix issue 14925 -- narrow strings should not match the first overload of replaceInPlace.

--
August 20, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

--- Comment #5 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/ea811edab97021c9328dd2e81c49bba23c414b4d Supplemental fix for issue 14925 - remove redundant conditions

https://github.com/D-Programming-Language/phobos/commit/de2df2bb04dfc4667ab0bac30425b9c14d6cb699 Merge pull request #3565 from 9rnsr/fix14925

Supplemental fix for issue 14925

--
October 04, 2015
https://issues.dlang.org/show_bug.cgi?id=14925

--- Comment #6 from github-bugzilla@puremagic.com ---
Commits pushed to stable at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/3f8b910e2c2834d2f87a543dc39692fe03a69c92 Fix issue 14925 -- merge overloads of replaceInPlace to avoid ambiguity

https://github.com/D-Programming-Language/phobos/commit/4d36627f363d9e23aae218578478a0c68da27278 Merge pull request #3561 from schveiguy/fix14925

https://github.com/D-Programming-Language/phobos/commit/ea811edab97021c9328dd2e81c49bba23c414b4d Supplemental fix for issue 14925 - remove redundant conditions

https://github.com/D-Programming-Language/phobos/commit/de2df2bb04dfc4667ab0bac30425b9c14d6cb699 Merge pull request #3565 from 9rnsr/fix14925

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=14925

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--