D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11524 - str.strip being shadowed by std.algorithm.strip
Summary: str.strip being shadowed by std.algorithm.strip
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-15 19:19 UTC by Hans Fugal
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Hans Fugal 2013-11-15 19:19:10 UTC
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 basile-z 2015-11-27 16:48:50 UTC
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.