summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-01-05 15:17:08 +0800
committerGitHub <noreply@github.com>2024-01-05 08:17:08 +0100
commit4eaa3b028cd8963799a637c8a4f7f553386fe395 (patch)
treeb3f91955b988a88e885814769e321b9447108e7d
parentc4f98b7696ce74c9952c973b0f09e59234f84917 (diff)
downloadNim-4eaa3b028cd8963799a637c8a4f7f553386fe395.tar.gz
fixes #23167; take `nkOpenSymChoice` into consideration caused by templates [backport] (#23168)
fixes #23167
-rw-r--r--compiler/modulepaths.nim16
-rw-r--r--tests/import/t23167.nim5
2 files changed, 15 insertions, 6 deletions
diff --git a/compiler/modulepaths.nim b/compiler/modulepaths.nim
index 73e0ef784..c9e6060e5 100644
--- a/compiler/modulepaths.nim
+++ b/compiler/modulepaths.nim
@@ -38,12 +38,16 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string =
           localError(n.info, "only '/' supported with $package notation")
           result = ""
     else:
-      if n0.kind == nkIdent and n0.ident.s[0] == '/':
-        let modname = getModuleName(conf, n[2])
-        # hacky way to implement 'x / y /../ z':
-        result = getModuleName(conf, n1)
-        result.add renderTree(n0, {renderNoComments}).replace(" ")
-        result.add modname
+      if n0.kind in nkIdentKinds:
+        let ident = n0.getPIdent
+        if ident != nil and ident.s[0] == '/':
+          let modname = getModuleName(conf, n[2])
+          # hacky way to implement 'x / y /../ z':
+          result = getModuleName(conf, n1)
+          result.add renderTree(n0, {renderNoComments}).replace(" ")
+          result.add modname
+        else:
+          result = ""
       else:
         result = ""
   of nkPrefix:
diff --git a/tests/import/t23167.nim b/tests/import/t23167.nim
new file mode 100644
index 000000000..0891ee2af
--- /dev/null
+++ b/tests/import/t23167.nim
@@ -0,0 +1,5 @@
+# bug #23167
+template sharedImport() =
+  import std / os
+
+sharedImport()