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. */
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.