Bug 11704 – std.conv.to fails from string to std.typecons.Typedef

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-12-07T07:09:15Z
Last change time
2024-12-01T16:19:29Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: phobos#10018 →

Comments

Comment #0 by bearophile_hugs — 2013-12-07T07:09:15Z
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));
Comment #1 by andrej.mitrovich — 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..).
Comment #2 by kdevel — 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)` [...]
Comment #3 by robert.schadek — 2024-12-01T16:19:29Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10018 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB