D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6730 - std.algorithm.splitter conflicts with std.array.splitter
Summary: std.algorithm.splitter conflicts with std.array.splitter
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: monarchdodra
URL:
Keywords: rejects-valid
: 10383 11701 (view as issue list)
Depends on:
Blocks:
 
Reported: 2011-09-25 11:11 UTC by bearophile_hugs
Modified: 2013-12-31 13:52 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-09-25 11:11:06 UTC
A D2 program:

import std.array, std.algorithm;
void main() {
    auto r = splitter("hello how are you");
}


DMD 2.056head gives:

test.d(3): Error: std.algorithm.splitter!(string).splitter at ...\dmd2\src\phobos\std\algorithm.d(2184) conflicts with std.array.splitter!(immutable(char)).splitter at ...\dmd2\src\phobos\std\array.d(1088)


Is this acceptable?
Comment 1 Jonathan M Davis 2011-09-25 14:19:59 UTC
In general, I'd say yes. The fact that two functions in different modules can have the same name and conflict is fully expected and acceptable. The module system gives a number of ways to get around the problem. That's not an issue.

However, in this case, what appears to be happening is that we have almost identical functions in two modules. The only difference between them is that the one in std.array will work with immutable strings, since it specifically types itself as taking an array, whereas std.algorithm's types itself as taking a range (though the range must be a string per the template constraint). If they did different things, that would be one thing, but I see no reason to have two identical functions. One of the two should be scheduled for deprecation.
Comment 2 monarchdodra 2012-10-22 23:09:27 UTC
(In reply to comment #1)
> In general, I'd say yes. The fact that two functions in different modules can
> have the same name and conflict is fully expected and acceptable. The module
> system gives a number of ways to get around the problem. That's not an issue.
> 
> However, in this case, what appears to be happening is that we have almost
> identical functions in two modules. The only difference between them is that
> the one in std.array will work with immutable strings, since it specifically
> types itself as taking an array, whereas std.algorithm's types itself as taking
> a range (though the range must be a string per the template constraint). If
> they did different things, that would be one thing, but I see no reason to have
> two identical functions. One of the two should be scheduled for deprecation.

Assigned to self.

Note that the one in std.algorithm is not documented, so anybody using it is
probably doing it by mistake.

My I outright remove it? Should I straight up give it deprecate it now? Do I
have to go the full deprecation route?
Comment 3 Jonathan M Davis 2012-10-22 23:16:16 UTC
I find it highly unlikely that they'd be using it by mistake, but since it's undocumented, it's not unreasonable to break code that's using it. However, it's probably still better to deprecate it first rather than outright remove it.
Comment 4 monarchdodra 2013-08-22 06:37:21 UTC
*** Issue 10383 has been marked as a duplicate of this issue. ***
Comment 5 Denis Shelomovskii 2013-10-02 23:46:09 UTC
Thing are really bad here as `std.range` which is often imported with `std.algorithm` publicly imports `std.array` so this will fail to compile:
---
import std.algorithm, std.range;

void main()
{ "".splitter(); }
---

Too bad. Lets do something with this.
Comment 6 monarchdodra 2013-10-03 00:24:49 UTC
(In reply to comment #5)
> Thing are really bad here as `std.range` which is often imported with
> `std.algorithm` publicly imports `std.array` so this will fail to compile:
> ---
> import std.algorithm, std.range;
> 
> void main()
> { "".splitter(); }
> ---
> 
> Too bad. Lets do something with this.

https://github.com/D-Programming-Language/phobos/pull/1502/files#diff-ff74a46362b5953e8c88120e2490f839R2824

I think a "short" deprecation plan (eg: 1 release) is called for here.
Comment 9 Walter Bright 2013-12-31 13:52:55 UTC
*** Issue 11701 has been marked as a duplicate of this issue. ***