[Issue 8509] New: Appending a string to an enum string results in another enum string

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 4 16:05:32 PDT 2012


           Summary: Appending a string to an enum string results in
                    another enum string
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com

--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2012-08-04 16:05:27 PDT ---
This code

enum E : string { a = "hello" }

void main()
    E e = E.a ~ " world";
    E f = E.a ~ 'w';

gives this compilation error:

q.d(6): Error: cannot implicitly convert expression ("hellow") of type string
to E

So, the compiler correctly recognizes that the result of appending a character
to an E results in a string rather than an E. However, it should _also_ fail on
appending a string to it. "hello world" is not a valid E, and appending an
arbitrary string to an enum of type string is not generally going to result in
a valid enum value, so the result should be typed as string, not the enum type.

If an operation on an enum type is not _guaranteed_ to result in a valid enum
value, then that operation should be illegal, forcing the programmer to cast
when they're sure that the result is valid and protecting them from invalid
assignments like in the example above.

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

More information about the Digitalmars-d-bugs mailing list