Bug 17187 – Error when using std.format.unformatValue with static arrays
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-02-15T20:00:42Z
Last change time
2019-12-10T13:47:17Z
Assigned to
No Owner
Creator
Jack Stouffer
Comments
Comment #0 by jack — 2017-02-15T20:00:42Z
auto str = "aaa";
auto spec = singleSpec("%s");
assert(str.unformatValue!(char[3])(spec) == ['a', 'a', 'a']);
std/conv.d(3877): Error: cannot implicitly convert expression (front(s)) of type dchar to char
std/conv.d(3881): Error: cannot implicitly convert expression (parseEscape(s)) of type dchar to char
std/format.d(4961): Error: template instance std.conv.parseElement!(char, string) error instantiating
std/format.d(4889): instantiated from here: unformatElement!(char, string, char)
std/format.d(4646): instantiated from here: unformatRange!(char[3], string, char)
std/format.d(4798): instantiated from here: unformatValue!(char[3], string, char)
std/range/primitives.d(347): Error: static assert "Cannot put a dchar into a char[]."
std/format.d(4668): instantiated from here: put!(char[], dchar)
std/format.d(4798): instantiated from here: unformatValue!(char[3], string, char)
Comment #1 by jack — 2017-02-15T20:02:23Z
BTW this is a bug because this works
auto str = "aaa";
auto spec = singleSpec("%s");
dchar[3] ret = ['a', 'a', 'a'];
assert(str.unformatValue!(dchar[3])(spec) == ret);
Comment #2 by bugzilla — 2019-12-06T13:03:06Z
I don't think this is a valid bug. In the second example you are converting from dchar to dchar while in the first you are converting from dchar to char. -- Imagine, the string contains three chinese symbols instead of `a`s. They never fit into char[3].