www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.string.split and std.regex.split conflict

reply Andrea Fontana <advmail katamail.com> writes:
dmd gives me this error:

Error: std.string.split at
/usr/include/d/dmd/phobos/std/string.d(70) conflicts with
std.regex.split(String) at
/usr/include/d/dmd/phobos/std/regex.d(2962)

It seems there's a name-conflict on standard library. How can I
solve it?

I've tried with dmd 2.054 64bit and 2.056 64bit both compiled by
myself on my ubuntu machine.
Sep 14 2011
next sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 14.09.2011 16:29, Andrea Fontana wrote:
 dmd gives me this error:

 Error: std.string.split at
 /usr/include/d/dmd/phobos/std/string.d(70) conflicts with
 std.regex.split(String) at
 /usr/include/d/dmd/phobos/std/regex.d(2962)

 It seems there's a name-conflict on standard library. How can I
 solve it?
For now you can solve it by using full name: std.regex.split or std.string.split or use selective imports on std.string to avoid split.
 I've tried with dmd 2.054 64bit and 2.056 64bit both compiled by
 myself on my ubuntu machine.
Yes, it's a bug, they should overload each other, it exists since std.regex inclusion maybe, I tried to fix this one in the past and failed. There is something about lookup rules I obviously don't get. -- Dmitry Olshansky
Sep 14 2011
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 14 Sep 2011 08:36:53 -0400, Dmitry Olshansky  
<dmitry.olsh gmail.com> wrote:

 On 14.09.2011 16:29, Andrea Fontana wrote:
 I've tried with dmd 2.054 64bit and 2.056 64bit both compiled by
 myself on my ubuntu machine.
Yes, it's a bug, they should overload each other, it exists since std.regex inclusion maybe, I tried to fix this one in the past and failed. There is something about lookup rules I obviously don't get.
No, the overload rules are specific. Two modules cannot overload each other. Otherwise, adding an import can change calls. Please read this part of the spec: http://www.d-programming-language.org/function.html#overload-sets -Steve
Sep 14 2011
parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 14.09.2011 16:58, Steven Schveighoffer wrote:
 On Wed, 14 Sep 2011 08:36:53 -0400, Dmitry Olshansky
 <dmitry.olsh gmail.com> wrote:

 On 14.09.2011 16:29, Andrea Fontana wrote:
 I've tried with dmd 2.054 64bit and 2.056 64bit both compiled by
 myself on my ubuntu machine.
Yes, it's a bug, they should overload each other, it exists since std.regex inclusion maybe, I tried to fix this one in the past and failed. There is something about lookup rules I obviously don't get.
No, the overload rules are specific. Two modules cannot overload each other. Otherwise, adding an import can change calls. Please read this part of the spec: http://www.d-programming-language.org/function.html#overload-sets
Anti-hijacking? I knew it, but it's not applicable here. I mean these functions should not conflict because their argument types do not intersect. You can't mistake Regex for String, these checks are present in template constraints, is it not enough? -- Dmitry Olshansky
Sep 14 2011
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 14 Sep 2011 09:10:28 -0400, Dmitry Olshansky  
<dmitry.olsh gmail.com> wrote:

 On 14.09.2011 16:58, Steven Schveighoffer wrote:
 On Wed, 14 Sep 2011 08:36:53 -0400, Dmitry Olshansky
 <dmitry.olsh gmail.com> wrote:

 On 14.09.2011 16:29, Andrea Fontana wrote:
 I've tried with dmd 2.054 64bit and 2.056 64bit both compiled by
 myself on my ubuntu machine.
Yes, it's a bug, they should overload each other, it exists since std.regex inclusion maybe, I tried to fix this one in the past and failed. There is something about lookup rules I obviously don't get.
No, the overload rules are specific. Two modules cannot overload each other. Otherwise, adding an import can change calls. Please read this part of the spec: http://www.d-programming-language.org/function.html#overload-sets
Anti-hijacking? I knew it, but it's not applicable here. I mean these functions should not conflict because their argument types do not intersect. You can't mistake Regex for String, these checks are present in template constraints, is it not enough?
I think there is more to it. The algorithm to process overloading from multiple overload sets is quite complex, and one of the problems of C++. I can't remember the name of it, but D just avoids it by not allowing multiple overload sets. In any case, it's not a bug, it's by design. -Steve
Sep 14 2011
next sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
 Anti-hijacking? I knew it, but it's not applicable here.
 I mean these functions should not conflict because their argument
 types do not intersect. You can't mistake Regex for String, these
 checks are present in template constraints, is it not enough?
I think there is more to it. The algorithm to process overloading from multiple overload sets is quite complex, and one of the problems of C++. I can't remember the name of it, but D just avoids it by not allowing multiple overload sets.
It is allowed from the same doc, as long as not ambiguous: import A; import B; void bar(C c) { foo(); // calls A.foo() foo(1L); // calls A.foo(long) foo(c); // calls B.foo(C) foo(1,2); // error, does not match any foo foo(1); // error, matches A.foo(long) and B.foo(int) A.foo(1); // calls A.foo(long) } I'm implying that in case where one overload set contains no valid functions (constraints fail) the other should be used.
 In any case, it's not a bug, it's by design.
Not so sure, maybe bug in phobos then. -- Dmitry Olshansky
Sep 14 2011
prev sibling parent reply Christian Kamm <kamm-incasoftware removethis.de> writes:
Steven Schveighoffer wrote:
 I can't remember the name of it, but D just avoids it by not allowing
 multiple overload sets.
 
 In any case, it's not a bug, it's by design.
It's not by design. Multiple overload sets are okay, as long as there are no ambiguities, see Dmitry's example. The problem is that std.string uses selective imports: public import std.array : join, split Test case: a.d: void foo() {} b.d: void foo(int) {} c.d: public import b : foo; use.d: import a; import b; // breaks if you import c instead void main() { foo(); foo(1); }
Sep 14 2011
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 14 Sep 2011 11:42:45 -0400, Christian Kamm  
<kamm-incasoftware removethis.de> wrote:

 Steven Schveighoffer wrote:
 I can't remember the name of it, but D just avoids it by not allowing
 multiple overload sets.

 In any case, it's not a bug, it's by design.
It's not by design. Multiple overload sets are okay, as long as there are no ambiguities, see Dmitry's example. The problem is that std.string uses selective imports: public import std.array : join, split Test case: a.d: void foo() {} b.d: void foo(int) {} c.d: public import b : foo; use.d: import a; import b; // breaks if you import c instead void main() { foo(); foo(1); }
OK, my apologies for not understanding the problem properly (or apparently overload resolution!) Sorry, I think you are right, it is a bug! -Steve
Sep 14 2011
prev sibling parent Brad Anderson <eco gnuk.net> writes:
On Wed, Sep 14, 2011 at 6:29 AM, Andrea Fontana <advmail katamail.com>wrote:

 dmd gives me this error:

 Error: std.string.split at
 /usr/include/d/dmd/phobos/std/string.d(70) conflicts with
 std.regex.split(String) at
 /usr/include/d/dmd/phobos/std/regex.d(2962)

 It seems there's a name-conflict on standard library. How can I
 solve it?
I encountered this same name conflict with an early code sample from The D Programming Language book. This should probably be added to the errata. I've tried with dmd 2.054 64bit and 2.056 64bit both compiled by
 myself on my ubuntu machine.
Regards, Brad Anderson
Sep 14 2011