Bug 12544 – Differences in ubyte/char enum printing

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-04-08T03:24:22Z
Last change time
2020-03-21T03:56:37Z
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-04-08T03:24:22Z
I am not sure if this is a bug, a regression, or it's working as designed. Currently this code shows a difference in the outputs that perhaps should not exist: void main() { import std.stdio; enum E1 : ubyte { A='a' } E1[10] v1; writeln(v1); enum E2 : char { A='a' } E2[10] v2; writeln(v2); writefln("%-(%c%)", v2); } DMD 2.066alpha output: [A, A, A, A, A, A, A, A, A, A] aaaaaaaaaa aaaaaaaaaa Expected output: [A, A, A, A, A, A, A, A, A, A] [A, A, A, A, A, A, A, A, A, A] aaaaaaaaaa
Comment #1 by monarchdodra — 2014-04-08T06:54:41Z
The code goes through the "formatRange" branch of `std.format`. In format range, the code checks if it is a range of chars: - range of chars => print string (eg: aaaaaaa...) - range of non-chars => print array (eg: [A, A, A, A, A... The issue is one of determining "what is a char"? Currently, the code uses: is(CharTypeOf!(ElementType!T)) Which mean any type that implicitly casts to char is fair game (including structs with "alias this"). *Arguably*, I think `isSomeChar` would be better, as it only accepts *actual* chars. But even then, it would still accept enums whose base type is char, as technically, they *are* chars. Unfortunately, there is always ambiguity when asking to print an enum of a char or string. I don't know either if this is bug or working as designed. (I don't think it's a regression though... did you test other versions?)
Comment #2 by b2.temp — 2015-11-27T16:04:02Z
ok now 2.069