Bug 9579 – std.regex.replace format argument should not require same constness as target string

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-23T17:03:00Z
Last change time
2013-08-16T22:09:26Z
Keywords
pull
Assigned to
dmitry.olsh
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2013-02-23T17:03:25Z
Code: // This works: auto re = regex(`a`, "g"); string input = "abc"; auto r = replace(input, re, "($1)"); // This gives a compile error: auto re = regex(`a`, "g"); char[] input; auto r = replace(input, re, "($1)"); The reason is that when input is char[], replace expects the format string to also be char[], but "($1)" is, by default, of type string. But this is unreasonable, because the constness of the format string shouldn't be tied to the constness of the target string! (Yes, DMD's IFTI has some limitations, it should be able in infer char[] instead of immutable(char)[], but regardless, there's no reason why the format argument must be char[].)
Comment #1 by dmitry.olsh — 2013-03-10T10:10:33Z
Comment #2 by github-bugzilla — 2013-08-16T16:35:14Z
Comment #3 by hsteoh — 2013-08-16T22:09:26Z
Confirmed it works now in git HEAD. Thanks Dmitry!