Issue 17542 - DSON conversion of enums misses enum name
Summary: DSON conversion of enums misses enum name
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-23 15:00 UTC by Vladimir Panteleev
Modified: 2024-12-01 16:30 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2017-06-23 15:00:48 UTC
This almost works:

///////////// test.d ////////////
import std.conv : text;
enum E { a }
struct S { E e; }
immutable S s1 = S.init;
immutable S s2 = mixin(text(s1));
/////////////////////////////////

It doesn't work because for the enum member a, std.format emits just "a" instead of "E.a".

std.format is already capable of converting the same type to string in different ways, e.g. format("%s", "hello") and format("%(%s%)", ["hello"]) will have the string converted differently (in the second case, with quotes and escapes).

So, it would be nice that for similar circumstances, stringified enums had their name included in the same way that stringified structs have their name included.

Incidentally, I found an interesting use case for DSON: parsing or generating a complicated data structure, dumping it to a .d file, then loading the .d file by using a mixin+import expression, for cases when generating said data directly at compile time would be too slow or otherwise impractical.
Comment 1 dlangBugzillaToGithub 2024-12-01 16:30:27 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10254

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB