[Issue 5666] std.array.replace compile error (string and immutable string)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 10 01:49:11 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5666


Jonathan M Davis <jmdavisProg at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |jmdavisProg at gmx.com
         Resolution|                            |INVALID


--- Comment #1 from Jonathan M Davis <jmdavisProg at gmx.com> 2011-03-10 01:46:09 PST ---
Of course that doesn't compile. Think about it for a moment. r is an
_immutable_ string. It _cannot_ change. Not only cannot you not alter any of
its elements (since the elements are immutable), but the reference itself is
immutable, so it can't be reassigned to another string. replace takes a
reference to the string that you pass it, creates a new string with the
replacement made in it, and then assigns the result to the original reference.
That won't work if the original is immutable. And in this case, it is. So, this
is not a bug. It is as designed. If you want to be able to use replace, you
need to do it on a mutable string (the elements can be immutable - a string is
immutable(char)[] after all - but the reference must be mutable).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list