Skip to content

Commit

Permalink
actually fix #19015 (#21680)
Browse files Browse the repository at this point in the history
* actually fix #19015

* more tests

* round out
  • Loading branch information
metagn authored Apr 17, 2023
1 parent 202b190 commit 9dc1f2d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions tests/misc/trfc405.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 9dc1f2d

Please sign in to comment.