Issue 16190 - to!string on enum should be fully qualified for consistency
Summary: to!string on enum should be fully qualified for consistency
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-21 18:13 UTC by Timothee Cour
Modified: 2024-12-01 16:27 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Timothee Cour 2016-06-21 18:13:16 UTC
enum A{
  a1,
  a2,
}

struct B{
  A b1;
  string b2;
  int c3;
}

import std.conv:to;

void main(){
  auto b=B(A.a1, "foo", 13);
  enum b_string=`B(a1, "foo", 13)`;
  assert(b.to!string == b_string);
  mixin(`auto b1=B(A.a1, "foo", 13);`);//works
  //mixin(`auto b2=`~b_string~`;`);//Error: undefined identifier 'a1'
}

Pretty much every type in D works when reconstructing as I did above:
mixin(`auto b2=`~b.to!string~`;`);
except when there's an enum type somewhere inside

What's a workaround?
Comment 1 basile-z 2016-06-21 19:01:55 UTC
I think that any fix directly in to() can break a lot of code because currently to!string and to!E work together. I'm sure that it's already used as it is now by many people.

The fix, if any, should maintain the old behvior and allow to get the identifier when explicitly needed, for example:

auto toImpl(T, S, bool fq = false)(auto ref E e)
if (is(S == enum) && is(T==string))
{}

with "fq" a CT bool that indicates if the output includes the "enum identifier".
"Fully qualified" would mean that even the module name would be included so I suppose that what you want is actually the enum identifier.

----

By the way why do you report this as a dmd (and not phobos) issue ?
Comment 2 dlangBugzillaToGithub 2024-12-01 16:27:18 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

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

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