[Issue 21227] New: import(".\\file") doesn't work on Windows

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 5 14:52:24 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21227

          Issue ID: 21227
           Summary: import(".\\file") doesn't work on Windows
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: andrey.zherikov at gmail.com

Imports with backslash doesn't work on Windows although backslash is a valid
path character there.

This can be reproduced with this:
======= test.d
void main()
{
    pragma(msg, import("./file"));
    pragma(msg, import(".\\file"));
}
======= file
hello
=======

Command to reproduce:
>dmd -J. -run test.d
hello

test.d(4): Error: file ".\\file" cannot be found or not in a path specified
with -J
test.d(4):        while evaluating pragma(msg, import(".\\file"))


DMD used to reproduce:
 - DMD32 D Compiler v2.091.0-dirty
 - latest master (DMD64 D Compiler v2.093.1-524-g1e09d998f)



The issue is in if condition here:
https://github.com/dlang/dmd/blob/master/src/dmd/root/filename.d#L744

And this change efficiently fixes it although I'm not sure whether something
else should be done:
diff --git a/src/dmd/root/filename.d b/src/dmd/root/filename.d
index 09810df8e..673582d0e 100644
--- a/src/dmd/root/filename.d
+++ b/src/dmd/root/filename.d
@@ -741,7 +741,7 @@ nothrow:
             for (const(char)* p = name; *p; p++)
             {
                 char c = *p;
-                if (c == '\\' || c == ':' || c == '%' || (c == '.' && p[1] ==
'.') || (c == '/' && p[1] == '/'))
+                if (c == ':' || c == '%' || (c == '.' && p[1] == '.') || (c ==
'/' && p[1] == '/'))
                 {
                     return null;
                 }

--


More information about the Digitalmars-d-bugs mailing list