This code works fine: int x = 7; Variant a = x; assert(a.convertsTo!ulong); This assert however triggers: int x = 7; Variant a = x; assert(a.convertsTo!uint); Is this behavior intended?
Looks like the problem is with std.traits.ImplicitConversionTargets: pragma(msg, ImplicitConversionTargets!int); //(long, ulong, float, double, real) But it appears to be intentional. From ImplicitConversionTargets: Note: The possible targets are computed more conservatively than the language allows, eliminating all dangerous conversions. For example, `ImplicitConversionTargets!double` does not include `float`. template ImplicitConversionTargets(T) { static if (is(T == bool)) .... else static if (is(T == int)) alias ImplicitConversionTargets = AliasSeq!(long, ulong, CentTypeList, float, double, real); else static if... } I don't know if it's better to change Variant or create a new, more permissible version of ImplicitConversionTargets.
@berni44 created dlang/phobos pull request #7842 "Fix Issue 18780 - Inconsistent behavior with Variant holding int converting to unsigned types" fixing this issue: - Fix Issue 18780 - Inconsistent behavior with Variant holding int converting to unsigned types https://github.com/dlang/phobos/pull/7842
@berni44 created dlang/phobos pull request #7954 "Fix Issue 18780 - Inconsistent behavior with Variant holding int converting to unsigned types" fixing this issue: - Fix Issue 18780 - Inconsistent behavior with Variant holding int converting to unsigned types https://github.com/dlang/phobos/pull/7954
dlang/phobos pull request #7954 "Fix Issue 18780 - Inconsistent behavior with Variant holding int converting to unsigned types" was merged into master: - 7afc9bff9d0547155a0e4a2755babcbe56599631 by berni44: Fix Issue 18780 - Inconsistent behavior with Variant holding int converting to unsigned types https://github.com/dlang/phobos/pull/7954