Skip to content

Commit

Permalink
Fix issue 10874.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
H. S. Teoh committed Aug 23, 2013
1 parent c3fa202 commit 8536853
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion std/conv.d
Expand Up @@ -1713,7 +1713,8 @@ a ConvException is thrown.
Enums with floating-point or string base types are not supported.
*/
T toImpl(T, S)(S value)
if (is(T == enum) && !is(S == enum) && is(S : OriginalType!T)
if (is(T == enum) && !is(S == enum)
&& is(typeof(value == OriginalType!T.init))
&& !isFloatingPoint!(OriginalType!T) && !isSomeString!(OriginalType!T))
{
foreach (Member; EnumMembers!T)
Expand Down Expand Up @@ -4089,3 +4090,11 @@ unittest
static assert(is(typeof(signed(cast(immutable T)1)) == long));
}
}

unittest
{
// issue 10874
enum Test { a = 0 }
ulong l = 0;
auto t = l.to!Test;
}

0 comments on commit 8536853

Please sign in to comment.