Bug 17190 – [REG2.072] isNumeric!string conflict std.traits std.string

Status
RESOLVED
Resolution
WONTFIX
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-02-16T23:18:59Z
Last change time
2020-03-21T03:56:35Z
Keywords
industry
Assigned to
No Owner
Creator
Johan Engelen

Comments

Comment #0 by jbc.engelen — 2017-02-16T23:18:59Z
Testcase: ```d // RUN: dmd -c test.d import std.string; import std.traits; void foo() { static if (isNumeric!string) {} } ``` When both std.string and std.traits are imported, dmd 2.072 and 2.073 error with: ``` isnum.d(6): Error: std.traits.isNumeric(T) at /Library/D/dmd/src/phobos/std/traits.d(5350) conflicts with std.string.isNumeric(S)(S s, bool bAllowSep = false) if (isSomeString!S || isRandomAccessRange!S && hasSlicing!S && isSomeChar!(ElementType!S) && !isInfinite!S) at /Library/D/dmd/src/phobos/std/string.d(5844) ``` dmd 2.070 and 2.071 compile it fine. I am not sure whether this is a bug or not. Thanks, Johan
Comment #1 by issues.dlang — 2017-02-16T23:53:49Z
It's a side effect of std.string.isNumeric being templatized in 2.072 to work with ranges rather than just strings. Before, it wasn't a template, so there was no ambiguity. Now it is a template, so the two symbols are ambiguous. It's unfortunate that it's caused problems, but it's not a bug. The only fix would be to change one of their names, but that would then break any code that used them. That being said, having a symbol that's an eponymous template have the same name as a symbol that's a function is bad planning, because they won't overload. Any code that imports both will have to either import one with a different name, or it will need to use the full import path when using them.
Comment #2 by b2.temp — 2017-04-27T19:45:22Z
option 1/ Renaming with deprecation is not like breaking: bool isNumber(S)(S s, bool bAllowSep = false) {} deprecated("use isNumber instead, ...") alias isNumeric = isNumber; option 2/ there's a simple fix, but it's not particularly nice: bool isNumeric(S, T = void)(S s){return false;} enum isNumeric(S) = true; static assert(isNumeric!string); static assert(!isNumeric("sdf"));
Comment #3 by issues.dlang — 2017-10-07T20:52:13Z
Comment #4 by bugzilla — 2018-05-17T04:07:23Z
(In reply to Jonathan M Davis from comment #3) > https://github.com/dlang/phobos/pull/5763 See discussion there as to why this is a WONTFIX.