Bug 11524 – str.strip being shadowed by std.algorithm.strip
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-15T19:19:10Z
Last change time
2020-03-21T03:56:36Z
Assigned to
No Owner
Creator
Hans Fugal
Comments
Comment #0 by hans — 2013-11-15T19:19:10Z
import std.string;
import std.stdio;
// OK
unittest {
string foo = " foo ";
writeln(foo.strip);
}
/* Not OK
strip.d(21): Error: template std.algorithm.strip does not match any function template declaration. Candidates are:
/usr/share/dmd/src/phobos/std/algorithm.d(7122): std.algorithm.strip(Range, E)(Range range, E element) if (isBidirectionalRange!Range && is(typeof(range.front == element) : bool))
/usr/share/dmd/src/phobos/std/algorithm.d(7129): std.algorithm.strip(alias pred, Range)(Range range) if (isBidirectionalRange!Range && is(typeof(pred(range.back)) : bool))
strip.d(21): Error: template std.algorithm.strip(Range, E)(Range range, E element) if (isBidirectionalRange!Range && is(typeof(range.front == element) : bool)) cannot deduce template function from argument types !()(string)
*/
unittest {
import std.algorithm;
string bar = " bar ";
writeln(bar.strip);
}
/* if I move "import std.algorithm;" outside of the unittest, it works fine. */
Comment #1 by b2.temp — 2015-11-27T16:48:50Z
This is not a bug, see:
http://dlang.org/module.html
partcularly this specification about scoped imports:
> The imports are looked up to satisfy any unresolved symbols at that scope. Imported symbols may hide symbols from outer scopes.
which means that in case of conflict, scoped imports win.