D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4972 - to!() needs a template constraint
Summary: to!() needs a template constraint
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 enhancement
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-01 22:58 UTC by Jonathan M Davis
Modified: 2015-06-09 05:15 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 Jonathan M Davis 2010-10-01 22:58:28 UTC
The following program

import std.conv;
import std.stdio;

void main()
{
    dchar[7] numStr = "1234567";

    writeln(to!long(numStr));
}


fails compilation with this error

/home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(95): Error: template std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) matches more than one template declaration, /home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(217):toImpl(T,S) if (isStaticArray!(S)) and /home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(588):toImpl(T,S) if ((is(S : const(wchar)[]) || is(S : const(dchar)[])) && !isSomeString!(T))
jmdavis@Lyonel ~/Programming/D/datetime [master]$ gvim /home/jmdavis/Downloaded_Files/dmd/dmd2/src/phobos/std/conv.d


The error gives no indication whatsoever where the actual error is. The problem is not in to!() but in the code that tried to instantiate to!(), and the error gives no way to find that code. Ideally, bug # 4970 would be fixed and the error would correctly indicate where to!() was used, but really, to!() should have a template constraint of its own. As it stands, it's guaranteed that any error instantiating to!() is not going to report the actual location of the error. Copying or moving toImpl!()'s template constraint to to!() would fix the problem quite easily, and I don't see much reason not to do it. It would certainly make errors with using to!() easier to fix.
Comment 1 Kenji Hara 2011-09-09 08:31:43 UTC
With pull #181, I did changed toImpl template constraint.

https://github.com/D-Programming-Language/phobos/pull/181

https://github.com/D-Programming-Language/phobos/commit/008300792cc18250106f9419cdf1e18dfa805846#L0L1738

After that, this problem was resolved.