[Issue 21174] New: Recognize string value from string enum

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 18 13:16:56 UTC 2020


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 at puremagic.com
          Reporter: apz28 at 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); 
}

--


More information about the Digitalmars-d-bugs mailing list