Issue 18780 - Inconsistent behavior with Variant holding int converting to unsigned types
Summary: Inconsistent behavior with Variant holding int converting to unsigned types
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2018-04-19 15:10 UTC by alex.jercaianu
Modified: 2021-04-13 08:02 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description alex.jercaianu 2018-04-19 15:10:53 UTC
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 Meta 2018-04-19 17:59:39 UTC
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 Dlang Bot 2021-03-11 20:45:26 UTC
@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 Dlang Bot 2021-04-12 07:56:36 UTC
@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 Dlang Bot 2021-04-13 08:02:10 UTC
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