Bug 18780 – Inconsistent behavior with Variant holding int converting to unsigned types

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-04-19T15:10:53Z
Last change time
2021-04-13T08:02:10Z
Keywords
pull
Assigned to
No Owner
Creator
alex.jercaianu

Comments

Comment #0 by alex.jercaianu — 2018-04-19T15:10:53Z
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?
Comment #1 by monkeyworks12 — 2018-04-19T17:59:39Z
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.
Comment #2 by dlang-bot — 2021-03-11T20:45:26Z
@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
Comment #3 by dlang-bot — 2021-04-12T07:56:36Z
@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
Comment #4 by dlang-bot — 2021-04-13T08:02:10Z
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