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. --- compiler/semstmts.nim | 27 +++++++++++++++------------ tests/modules/mincludeprefix.nim | 1 + tests/modules/mincludetemplate.nim | 1 + tests/modules/tincludeprefix.nim | 3 +++ tests/modules/tincludetemplate.nim | 5 +++++ 5 files changed, 25 insertions(+), 12 deletions(-) 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 diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index be60b093d..ce928eef9 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -2735,20 +2735,23 @@ proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) = proc evalInclude(c: PContext, n: PNode): PNode = result = newNodeI(nkStmtList, n.info) result.add n + template checkAs(it: PNode) = + if it.kind == nkInfix and it.len == 3: + let op = it[0].getPIdent + if op != nil and op.id == ord(wAs): + localError(c.config, it.info, "Cannot use '" & it[0].renderTree & "' in 'include'.") for i in 0..