summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSirOlaf <34164198+SirOlaf@users.noreply.github.com>2022-10-18 20:56:38 +0200
committerGitHub <noreply@github.com>2022-10-18 14:56:38 -0400
commit2f441ac6754e76f936900f4f4641587a82967f71 (patch)
tree9741d993f8e72df02ffc048847c78f993afdc2ab
parentb07526b2c77c75484d6008ea37d13cf022830c1a (diff)
downloadNim-2f441ac6754e76f936900f4f4641587a82967f71.tar.gz
[backport] Handle nkOpenSymChoice for nkAccQuoted in considerQuotedIdent (#20578)
* Handle nkOpenSymChoice for nkAccQuoted in considerQuotedIdent

* Add test

* Update compiler/lookups.nim

Co-authored-by: SirOlaf <a>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r--compiler/lookups.nim5
-rw-r--r--tests/template/template_various.nim15
2 files changed, 20 insertions, 0 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim
index a2f3d53a0..2121982a6 100644
--- a/compiler/lookups.nim
+++ b/compiler/lookups.nim
@@ -48,6 +48,11 @@ proc considerQuotedIdent*(c: PContext; n: PNode, origin: PNode = nil): PIdent =
         case x.kind
         of nkIdent: id.add(x.ident.s)
         of nkSym: id.add(x.sym.name.s)
+        of nkSymChoices:
+          if x[0].kind == nkSym:
+            id.add(x[0].sym.name.s)
+          else:
+            handleError(n, origin)
         of nkLiterals - nkFloatLiterals: id.add(x.renderTree)
         else: handleError(n, origin)
       result = getIdent(c.cache, id)
diff --git a/tests/template/template_various.nim b/tests/template/template_various.nim
index 6b1290fb9..a3b549e18 100644
--- a/tests/template/template_various.nim
+++ b/tests/template/template_various.nim
@@ -353,3 +353,18 @@ block gensym3:
   echo a ! b ! c ! d
   echo a ! b ! c ! d ! e
   echo x,y,z
+
+
+block identifier_construction_with_overridden_symbol:
+  # could use add, but wanna make sure it's an override no matter what
+  func examplefn = discard
+  func examplefn(x: int) = discard
+
+  # the function our template wants to use
+  func examplefn1 = discard
+
+  template exampletempl(n) =
+    # attempt to build a name using the overridden symbol "examplefn"
+    `examplefn n`()
+
+  exampletempl(1)