Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSON conversion of enums misses enum name #10254

Open
dlangBugzillaToGithub opened this issue Jun 23, 2017 · 0 comments
Open

DSON conversion of enums misses enum name #10254

dlangBugzillaToGithub opened this issue Jun 23, 2017 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

dlang-bugzilla (@CyberShadow) reported this on 2017-06-23T15:00:48Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=17542

Description

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.
@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants