summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-04-17 21:56:52 +0300
committerGitHub <noreply@github.com>2023-04-17 20:56:52 +0200
commit9dc1f2dd0f8dc08552338ca55e54a5305272d42d (patch)
tree0172a3945782d55a6b770073014c4a7b8297048d
parent202b1904733845a8015acc36738b9413f78b3cbe (diff)
downloadNim-9dc1f2dd0f8dc08552338ca55e54a5305272d42d.tar.gz
actually fix #19015 (#21680)
* actually fix #19015

* more tests

* round out
-rw-r--r--compiler/sigmatch.nim4
-rw-r--r--tests/misc/trfc405.nim28
2 files changed, 31 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 76c04e693..ad88ed7b2 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -2389,7 +2389,9 @@ proc findFirstArgBlock(m: var TCandidate, n: PNode): int =
     # checking `nfBlockArg in n[a2].flags` wouldn't work inside templates
     if n[a2].kind != nkStmtList: break
     let formalLast = m.callee.n[m.callee.n.len - (n.len - a2)]
-    if formalLast.kind == nkSym and formalLast.sym.ast == nil:
+    # parameter has to occupy space (no default value, not void or varargs)
+    if formalLast.kind == nkSym and formalLast.sym.ast == nil and
+        formalLast.sym.typ.kind notin {tyVoid, tyVarargs}:
       result = a2
     else: break
 
diff --git a/tests/misc/trfc405.nim b/tests/misc/trfc405.nim
index 8c967eb77..0828879ee 100644
--- a/tests/misc/trfc405.nim
+++ b/tests/misc/trfc405.nim
@@ -79,6 +79,34 @@ template main =
       foobar3
       foobar4
     doAssert a2 == (1, 20, "\nfoobar1\nfoobar2", "\nfoobar3\nfoobar4")
+  
+  block: # issue #19015
+    template hi(a: untyped, b: varargs[untyped]): untyped =
+      a
+
+    var worked = false
+    hi:
+      worked = true
+    doAssert worked
+    worked = false
+    hi(doAssert(not worked)):
+      doesntCompile
+    hi(doAssert(not worked), doesntCompile, againDoesntCompile):
+      definitelyDoesntCompile
+
+    template hi2(a: bool, b: untyped, c: varargs[untyped]): untyped =
+      b
+      doAssert a
+
+    hi2 worked:
+      worked = true
+    doAssert worked
+    hi2 worked, doAssert(worked):
+      doesntCompile
+    hi2 worked, doAssert(worked), doesntCompile, againDoesntCompile:
+      definitelyDoesntCompile
+    hi2 worked, doAssert(worked), againDoesntCompile:
+      definitelyDoesntCompile
 
 static: main()
 main()