Skip to content

Commit 9fadf8a

Browse files
katyukhadlang-bot
authored andcommitted
std.path.expandTilde: make compatible with scope and preview='in'
When using `expandTilde` with 'priview=in' enabled, it requires to duplicate value to be able to call this function. Within this commit the signature of expandTilde function is changed from `string expandTilde(string inputPath) @safe nothrow` to `string expandTilde(return scope const string inputPath) @safe nothrow` thus, after this commit it is possible to use this func in scope context. Example case: ```d /+ dub.sdl: name "dub-example" dflags "-preview=in" "-preview=dip1000" +/ import std.stdio; import std.path; @safe: string fun(in string path) { return path.expandTilde; } void main() { string p = fun("~/tests/1"); writefln("P: %s", p); } ```
1 parent 9df5eff commit 9fadf8a

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

std/path.d

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3955,7 +3955,7 @@ if (isConvertibleToString!Range)
39553955
}
39563956
-----
39573957
*/
3958-
string expandTilde(string inputPath) @safe nothrow
3958+
string expandTilde(return scope const string inputPath) @safe nothrow
39593959
{
39603960
version (Posix)
39613961
{
@@ -4138,7 +4138,7 @@ string expandTilde(string inputPath) @safe nothrow
41384138
}
41394139

41404140
///
4141-
@system unittest
4141+
@safe unittest
41424142
{
41434143
version (Posix)
41444144
{
@@ -4153,7 +4153,7 @@ string expandTilde(string inputPath) @safe nothrow
41534153
}
41544154
}
41554155

4156-
@system unittest
4156+
@safe unittest
41574157
{
41584158
version (Posix)
41594159
{
@@ -4205,6 +4205,26 @@ string expandTilde(string inputPath) @safe nothrow
42054205
}
42064206
}
42074207

4208+
@safe unittest
4209+
{
4210+
version (Posix)
4211+
{
4212+
import std.process : environment;
4213+
4214+
string testPath(scope const string source_path) {
4215+
return source_path.expandTilde;
4216+
}
4217+
4218+
auto oldHome = environment["HOME"];
4219+
scope(exit) environment["HOME"] = oldHome;
4220+
4221+
environment["HOME"] = "dmd/test";
4222+
assert(testPath("~/") == "dmd/test/");
4223+
assert(testPath("~") == "dmd/test");
4224+
}
4225+
}
4226+
4227+
42084228
version (StdUnittest)
42094229
{
42104230
private:

0 commit comments

Comments
 (0)