www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21174] New: Recognize string value from string enum

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

          Issue ID: 21174
           Summary: Recognize string value from string enum
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: apz28 hotmail.com

enum E
{
        text1 = "text1",
        text2  = "text2",
}

enum E2 : string
{
        text1 = "text1",
        text2  = "text2",
}

struct S
{
 safe:

public:
    this(T)(T value) nothrow
    if (is(T == bool) || is(T == int) || is(T == string))
    {}
}

void main()
{
    int a = 1;

    // Not work 
    //cannot deduce function from argument types !()(E)
    auto s = S(a == 1 ? E.text1 : E.text2); 
    //cannot deduce function from argument types !()(E2)
    auto s2 = S(a == 1 ? E2.text1 : E2.text2); 

    //work
    string t = a == 1 ? E.text1 : E.text2;
    auto s3 = S(t); 
}

--
Aug 18 2020