From 4eaa3b028cd8963799a637c8a4f7f553386fe395 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 5 Jan 2024 15:17:08 +0800 Subject: [PATCH] fixes #23167; take `nkOpenSymChoice` into consideration caused by templates [backport] (#23168) fixes #23167 --- compiler/modulepaths.nim | 16 ++++++++++------ tests/import/t23167.nim | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 tests/import/t23167.nim diff --git a/compiler/modulepaths.nim b/compiler/modulepaths.nim index 73e0ef7849..c9e6060e5e 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 0000000000..0891ee2afa --- /dev/null +++ b/tests/import/t23167.nim @@ -0,0 +1,5 @@ +# bug #23167 +template sharedImport() = + import std / os + +sharedImport()