www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10874] New: std.conv.to should support conversion from ulong to int-based enum

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10874

           Summary: std.conv.to should support conversion from ulong to
                    int-based enum
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: hsteoh quickfur.ath.cx


--- Comment #0 from hsteoh quickfur.ath.cx 2013-08-22 18:54:49 PDT ---
Code:
------
import std.conv;
enum Test { a = 0 }
void main() {
    ulong l = 0;
    auto t = l.to!Test;
}
------

DMD output:

/usr/src/d/phobos/std/conv.d(281): Error: template std.conv.toImpl does not
match any function template declaration. Candidates are:
/usr/src/d/phobos/std/conv.d(337):        std.conv.toImpl(T, S)(S value) if
(isImplicitlyConvertible!(S, T) && !isEnumStrToStr!(S, T) && !isNullToStr!(S,
T))
/usr/src/d/phobos/std/conv.d(449):        std.conv.toImpl(T, S)(ref S s) if
(isRawStaticArray!S)
/usr/src/d/phobos/std/conv.d(465):        std.conv.toImpl(T, S)(S value) if
(is(typeof(S.init.opCast!T()) : T) && !isExactSomeString!T)
/usr/src/d/phobos/std/conv.d(496):        std.conv.toImpl(T, S)(S value) if
(!isImplicitlyConvertible!(S, T) && is(T == struct) && is(typeof(T(value))))
/usr/src/d/phobos/std/conv.d(546):        std.conv.toImpl(T, S)(S value) if
(!isImplicitlyConvertible!(S, T) && is(T == class) && is(typeof(new T(value))))
/usr/src/d/phobos/std/conv.d(281):        ... (16 more, -v to show) ...
/usr/src/d/phobos/std/conv.d(281): Error: template std.conv.toImpl(T, S)(S
value) if (isImplicitlyConvertible!(S, T) && !isEnumStrToStr!(S, T) &&
!isNullToStr!(S, T)) cannot deduce template function from argument types
!(Test)(ulong)
/usr/src/d/phobos/std/conv.d(281): Error: template instance toImpl!(Test)
errors instantiating template
test.d(5): Error: template instance std.conv.to!(Test).to!(ulong) error
instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 22 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10874


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from hsteoh quickfur.ath.cx 2013-08-22 21:07:02 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1505

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10874



--- Comment #2 from github-bugzilla puremagic.com 2013-08-24 02:33:44 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/8536853fc86632883d6ad18096b4980bacbb5056
Fix issue 10874.

Don't assume that is(A : B) means a==b is valid, or that !is(A : B)
implies that a==b is invalid. Instead, test for a==b explicitly.

More specifically, int and ulong are ==-comparable, even though ulong is
not implicitly convertible to int. Thus, one should be able to convert
ulong to an int-based enum, but is(A : B) in the signature constraint
prohibits this. Testing for a==b explicitly, OTOH, makes this work.

https://github.com/D-Programming-Language/phobos/commit/a184d6b484c3f2968c379f48c6fff42828b98375
Merge pull request #1505 from quickfur/issue10874

Issue 10874 - conv.to ulong to int enum conversion

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 24 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10874


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |monarchdodra gmail.com
         Resolution|                            |FIXED


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