www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Is this a known issue in Phobos/DMD?

reply d coder <dlang.coder gmail.com> writes:
--20cf303f69e894d2b904d28cd319
Content-Type: text/plain; charset=ISO-8859-1

Greetings

When I compile the code below, I unexpectedly get an error:
test.d(7): Error: template std.string.format does not match any function
template declaration. Candidates are:
/home/puneet/local/github-d/bin/../phobos/std/string.d(2528):
 std.string.format(Char, Args...)(in Char[] fmt, Args args)
test.d(7): Error: template std.string.format(Char, Args...)(in Char[] fmt,
Args args) cannot deduce template function from argument types
!()(string,void)

There are a couple of issues involved here.
1. std.string is exposing "count" (and some other functions) from
std.algorithm. I think this should be a bug since count is not listed as a
method in the std.string documentation.
2. Now the function from std.algorithm that becomes visible, shadows the
local argument count. Is this expected behavior? If not, has it already
been reported as a bug? At the minimum I expect better error message here.

Thanks and Regards
- Puneet


void main() {                   // 1
  foo(4);                       // 2
}                               // 3
                                // 4
void foo(int count) {           // 5
  import std.string;            // 6
  format("%s", count);          // 7
}                               // 8

--20cf303f69e894d2b904d28cd319
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div><font face=3D"arial, helvetica, sans-serif">Greetings</font></div><div=
<font face=3D"arial, helvetica, sans-serif"><br></font></div><div><font fa=

ctedly get an error:</font></div> <div><font face=3D"arial, helvetica, sans-serif"><div>test.d(7): Error: tem= plate std.string.format does not match any function template declaration. C= andidates are:</div><div>/home/puneet/local/github-d/bin/../phobos/std/stri= ng.d(2528): =A0 =A0 =A0 =A0std.string.format(Char, Args...)(in Char[] fmt, = Args args)</div> <div>test.d(7): Error: template std.string.format(Char, Args...)(in Char[] = fmt, Args args) cannot deduce template function from argument types !()(str= ing,void)</div><div><br></div><div>There are a couple of issues involved he= re.</div> <div>1. std.string is exposing &quot;count&quot; (and some other functions)= from std.algorithm. I think this should be a bug since count is not listed= as a method in the std.string documentation.</div><div>2. Now the function= from std.algorithm that becomes visible, shadows the local argument count.= Is this expected behavior? If not, has it already been reported as a bug? = At the minimum I expect better error message here.</div> <div><br></div><div>Thanks and Regards</div><div>- Puneet</div><div><br></d= iv></font></div><div><font face=3D"courier new, monospace"><br></font></div=
<div><font face=3D"courier new, monospace">void main() { =A0 =A0 =A0 =A0 =

<div><font face=3D"courier new, monospace">=A0 foo(4); =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 // 2</font></div><div><font face=3D"courier new, mo= nospace">} =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // 3= </font></div><div><font face=3D"courier new, monospace">=A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // 4</font></div> <div><font face=3D"courier new, monospace">void foo(int count) { =A0 =A0 = =A0 =A0 =A0 // 5</font></div><div><font face=3D"courier new, monospace">=A0= import std.string; =A0 =A0 =A0 =A0 =A0 =A0// 6</font></div><div><font face= =3D"courier new, monospace">=A0 format(&quot;%s&quot;, count); =A0 =A0 =A0 = =A0 =A0// 7</font></div> <div><font face=3D"courier new, monospace">} =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 // 8</font></div><div><br></div> --20cf303f69e894d2b904d28cd319--
Jan 05 2013
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 01/05/2013 05:09 PM, d coder wrote:
 Greetings

 When I compile the code below, I unexpectedly get an error:
 test.d(7): Error: template std.string.format does not match any function
 template declaration. Candidates are:
 /home/puneet/local/github-d/bin/../phobos/std/string.d(2528):
   std.string.format(Char, Args...)(in Char[] fmt, Args args)
 test.d(7): Error: template std.string.format(Char, Args...)(in Char[]
 fmt, Args args) cannot deduce template function from argument types
 !()(string,void)

 There are a couple of issues involved here.
 1. std.string is exposing "count" (and some other functions) from
 std.algorithm. I think this should be a bug since count is not listed as
 a method in the std.string documentation.
 2. Now the function from std.algorithm that becomes visible, shadows the
 local argument count. Is this expected behavior? If not, has it already
 been reported as a bug? At the minimum I expect better error message here.

 Thanks and Regards
 - Puneet


 void main() {                   // 1
    foo(4);                       // 2
 }                               // 3
                                  // 4
 void foo(int count) {           // 5
    import std.string;            // 6
    format("%s", count);          // 7
 }                               // 8

I think it is a bug, but there is no documentation. http://d.puremagic.com/issues/show_bug.cgi?id=7329 The part about count is caused by Phobos. (from std.string: //Remove when repeat is finally removed. They're only here as part of the //deprecation of these functions in std.string. public import std.algorithm : startsWith, endsWith, cmp, count; )
Jan 06 2013