Thread overview
[Issue 10560] New: Enum typed as int with value equal to 0 or 1 prefer bool over int overload
Jul 07, 2013
Maxim Fomin
July 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10560

           Summary: Enum typed as int with value equal to 0 or 1 prefer
                    bool over int overload
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: yazan.dabain@gmail.com


--- Comment #0 from yazan.dabain@gmail.com 2013-07-06 14:24:31 PDT ---
import std.stdio;

void foo(bool b) { writeln("bool"); }
void foo(int i) { writeln("int"); }

enum Boo : int {
  a = 1,
  b = 2,
}

void main() {
  foo(Boo.a); //prints 'bool', should print int
  foo(Boo.b); //prints 'int' correctly
}

This issue is related to http://d.puremagic.com/issues/show_bug.cgi?id=9999

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10560


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-07-07 00:21:26 PDT ---
This is a separate issue. Boo should be Boo in the first place and int in the second. In referenced issue bool and long are overloaded, here are bool and int. If you pass 1 in such case int version should be called. Problem here is that int was converted to bool and passed to bool overload instead of int which is a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10560



--- Comment #2 from yazan.dabain@gmail.com 2013-07-07 13:44:11 PDT ---
I certainly agree. I just wanted to note the explanation on why an int 'literal' of 1 would match a bool overload in the first place.

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