www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17160] New: Apparently faulty behavior comparing enum members

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

          Issue ID: 17160
           Summary: Apparently faulty behavior comparing enum members
                    using `is`
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: meapineapple gmail.com

With DMD v2.072.2 on Windows 7 this code produces an assertion error:

    unittest{
        enum Enum: double{A = 0.1}
        bool test(in Enum a){return a is Enum.A;}
        assert(test(Enum.A));
    }

When `A = 1` or other values that can be represented more exactly as a floating
point, the code does not produce an error.

Given that this code does not produce such an error, I'm especially inclined to
think this is not intended behavior:

    unittest{
        enum Enum: double{A = 0.1}
        assert(Enum.A is Enum.A);
    }

--
Feb 08 2017