dlangBugzillaToGithub / migration_test

0 stars 0 forks source link

std.conv.to fails from string to std.typecons.Typedef #799

Open dlangBugzillaToGithub opened 10 years ago

dlangBugzillaToGithub commented 10 years ago

bearophile_hugs reported this on 2013-12-07T07:09:15Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=11704

CC List

Description

void main() {
    import std.typecons: Typedef;
    import std.conv: to;
    alias T = Typedef!int;
    string x = "5";
    T y = to!T(x);
}

dmd 2.065alpha gives:

...\dmd2\src\phobos\std\conv.d(281): Error: template std.conv.toImpl does not match any function template declaration. Candidates are:
...\dmd2\src\phobos\std\conv.d(346):        std.conv.toImpl(T, S)(S value) if (isImplicitlyConvertible!(S, T) && !isEnumStrToStr!(S, T) && !isNullToStr!(S, T))
...\dmd2\src\phobos\std\conv.d(458):        std.conv.toImpl(T, S)(ref S s) if (isRawStaticArray!S)
...\dmd2\src\phobos\std\conv.d(474):        std.conv.toImpl(T, S)(S value) if (!isImplicitlyConvertible!(S, T) && is(typeof(S.init.opCast!T()) : T) && !isExactSomeString!T)
...\dmd2\src\phobos\std\conv.d(506):        std.conv.toImpl(T, S)(S value) if (!isImplicitlyConvertible!(S, T) && is(T == struct) && is(typeof(T(value))))
...\dmd2\src\phobos\std\conv.d(556):        std.conv.toImpl(T, S)(S value) if (!isImplicitlyConvertible!(S, T) && is(T == class) && is(typeof(new T(value))))
...\dmd2\src\phobos\std\conv.d(281):        ... (16 more, -v to show) ...
...\dmd2\src\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 !(Typedef!(int, 0))(string)
temp.d(6): Error: template instance std.conv.to!(Typedef!(int, 0)).to!(string) error instantiating

A workaround:

T y = T(to!int(x));
dlangBugzillaToGithub commented 10 years ago

andrej.mitrovich commented on 2014-04-22T21:20:45Z

This is really just one specific case of Typedef not being handled. I bet a lot of Phobos code simply doesn't work with Typedef. I'm not sure whether it's worth adding support, it might open a can of worms (or enhancement requests..).
dlangBugzillaToGithub commented 3 months ago

kdevel commented on 2024-09-01T01:06:44Z

Same error opposite direction:

void main ()
{
   import std.typecons;
   import std.conv;

   alias vstring = Typedef!string;
   auto v = 3.to!vstring;
}

../../src/phobos/std/conv.d(210): Error: none of the overloads of template `std.conv.toImpl` are callable using argument types `!(Typedef!(string, null, null))(int)`
[...]