← Back to index
|
Original Bugzilla link
Bug 10874 – std.conv.to should support conversion from ulong to int-based enum
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-22T18:54:00Z
Last change time
2013-08-24T02:37:41Z
Keywords
pull
Assigned to
nobody
Creator
hsteoh
Comments
Comment #0
by hsteoh — 2013-08-22T18:54:49Z
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
Comment #1
by hsteoh — 2013-08-22T21:07:02Z
https://github.com/D-Programming-Language/phobos/pull/1505
Comment #2
by github-bugzilla — 2013-08-24T02:33:44Z
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