From d7e77b330f3f84a9cebcca057c0697687ebe8ec3 Mon Sep 17 00:00:00 2001 From: metagn Date: Thu, 29 Aug 2024 17:11:37 +0300 Subject: fix `include` in templates, with prefix operators (#24029) fixes #12539, refs #21636 `evalInclude` now uses `getPIdent` to check if a symbol isn't `/` anymore instead of assuming it's an ident, which it's not when used in templates. Also it just checks if the symbol is `as` now, because there are other infix operators that could be used like `/../`. It also works with prefix operators now by copying what was done in #21636. --- tests/modules/mincludeprefix.nim | 1 + tests/modules/mincludetemplate.nim | 1 + tests/modules/tincludeprefix.nim | 3 +++ tests/modules/tincludetemplate.nim | 5 +++++ 4 files changed, 10 insertions(+) create mode 100644 tests/modules/mincludeprefix.nim create mode 100644 tests/modules/mincludetemplate.nim create mode 100644 tests/modules/tincludeprefix.nim create mode 100644 tests/modules/tincludetemplate.nim (limited to 'tests') diff --git a/tests/modules/mincludeprefix.nim b/tests/modules/mincludeprefix.nim new file mode 100644 index 000000000..6d557a430 --- /dev/null +++ b/tests/modules/mincludeprefix.nim @@ -0,0 +1 @@ +const bar = 456 diff --git a/tests/modules/mincludetemplate.nim b/tests/modules/mincludetemplate.nim new file mode 100644 index 000000000..febe9bfcf --- /dev/null +++ b/tests/modules/mincludetemplate.nim @@ -0,0 +1 @@ +const foo = 123 diff --git a/tests/modules/tincludeprefix.nim b/tests/modules/tincludeprefix.nim new file mode 100644 index 000000000..d45a6eff3 --- /dev/null +++ b/tests/modules/tincludeprefix.nim @@ -0,0 +1,3 @@ +include ./[mincludeprefix, mincludetemplate] +doAssert foo == 123 +doAssert bar == 456 diff --git a/tests/modules/tincludetemplate.nim b/tests/modules/tincludetemplate.nim new file mode 100644 index 000000000..77e409ee5 --- /dev/null +++ b/tests/modules/tincludetemplate.nim @@ -0,0 +1,5 @@ +# issue #12539 + +template includePath(n: untyped) = include ../modules/n # But `include n` works +includePath(mincludetemplate) +doAssert foo == 123 -- cgit 1.4.1-2-gfad0