www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16190] New: to!string on enum should be fully qualified for

https://issues.dlang.org/show_bug.cgi?id=16190

          Issue ID: 16190
           Summary: to!string on enum should be fully qualified for
                    consistency
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timothee.cour2 gmail.com

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?

--
Jun 21 2016