Thread overview
[Issue 4883] New: std.algorithm functions conflict with std.string fucntions
Sep 17, 2010
Seth A Hoenig
Nov 09, 2010
Per Ångström
Nov 09, 2010
Jonathan M Davis
September 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4883

           Summary: std.algorithm functions conflict with std.string
                    fucntions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: seth.a.hoenig@gmail.com


--- Comment #0 from Seth A Hoenig <seth.a.hoenig@gmail.com> 2010-09-17 15:00:00 PDT ---
Given these two minimal programs:

import std.string;
void main()
{
    string str = "abc";
    int i = str.count("ab");

}


and:


import std.string;
import std.algorithm;
void main()
{
    string str = "abc";
    int i = str.count("ab");

}


The only difference is line 2, where I import std.algorithm.
The first program compiles fine, but the second program does not compile,
spitting out the error message:



bash-3.2$ dmd -ofdummy dummy.d
/u/sah2659/dmd2/linux/bin/../../src/phobos/std/functional.d(176): Error: static
assert  "Bad binary function q{a == b}. You need to use a valid D expression
using symbols a of type dchar and b of type string."
/u/sah2659/dmd2/linux/bin/../../src/phobos/std/functional.d(179):
instantiated from here: Body!(dchar,string)
/u/sah2659/dmd2/linux/bin/../../src/phobos/std/algorithm.d(3410):
instantiated from here: result!(dchar,string)
dummy.d(7):        instantiated from here: count!("a == b",string,string)



A little more investigating reveals that std.algorithm.indexOf and std.string.indexOf also conflict.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4883


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2010-09-19 17:52:14 PDT ---
As Phobos grows, it's harder and harder to to invent all distinct nice names for all its modules, and keep those name not too much long. In this case it may be better to change function names, but in general you need to learn to use qualified imports, and even renamed imports when necessary.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4883


Per Ångström <d-bugzilla@autark.se> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |d-bugzilla@autark.se


--- Comment #2 from Per Ångström <d-bugzilla@autark.se> 2010-11-09 09:20:47 PST ---
(Digital Mars D Compiler v2.050)
I get the same error message without even importing std.string:

$ cat count.d
import std.algorithm;
void main()
{
    string str = "abc";
    int i = str.count("ab");

}

$ dmd count.d
/usr/include/d/dmd/phobos/std/functional.d(176): Error: static assert  "Bad
binary function q{a == b}. You need to use a valid D expression using symbols a
of type dchar and b of type string."
/usr/include/d/dmd/phobos/std/functional.d(179):        instantiated from here:
Body!(dchar,string)
/usr/include/d/dmd/phobos/std/algorithm.d(3300):        instantiated from here:
result!(dchar,string)
count.d(5):        instantiated from here: count!("a == b",string,string)
Even though I don't expect the program to compile successfully, I find it odd
that the compiler picks up std.algorithm.count at all, when I'm using the
object.member notation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4883


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #3 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-11-09 10:21:08 PST ---
The object.member notation is generally irrelevant unless it's actually a member function. str.count("ab") will be changed to count(str, "ab") and any overload resolution will be taken care of that way. The fact that count() is a template function in std.algorithm and not in std.string probably doesn't help any either, given how you can't currently overload functions where one is a template and one not (though they'd be in different overload sets in this case).

Regardless, using

alias std.string.count count;

should fix the problem, allowing you to use the string version without having to write std.string.count(str, "ab"). Still, it would be better if std.string and std.algorithm would avoid name clashes, since they're so likely to conflict. At least some of the name clashes should be going away though as functions are consolidated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4883


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4883


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #4 from Andrei Alexandrescu <andrei@metalanguage.com> 2011-01-21 21:52:52 PST ---
Fixed by diffs

http://www.dsource.org/projects/phobos/changeset/N

where N is 2339, 2340, 2341, 2342, 2343, 2349, 2350, 2354

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------