New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot call template/macros with varargs[typed] to varargs[untyped] #10075

slangmgh opened this Issue Dec 22, 2018 · 3 comments


None yet
2 participants
Copy link

slangmgh commented Dec 22, 2018

The following code works with develop version of v0.18.0, but doesn't works for v 0.19.0

import macros

proc convert_hidden_stdconv(args: NimNode): NimNode =
   var n = args
   while n.len == 1 and n[0].kind == nnkHiddenStdConv:
      n = n[0][1]
   return n

macro t2(s: int, v: varargs[untyped]): untyped =
   let v = convert_hidden_stdconv(v)
   echo v.treeRepr
   let (v1, v2) = (v[0], v[1])
   quote do:
      echo `v1`, " ", `v2`

template t1(s: int, v: varargs[typed]) =
   #   dumpTree v
   echo s
   t2(s, v)

when isMainModule:
   t1(10, "hello", 18.0)

The compiler error is:

Error: unhandled exception: D:\Tool\Nim\compiler\sigmatch.nim(2236, 18) `n.sons[a].sons[0].kind == nkEmpty and n.sons[a].sons[1].kind == nkArgList and
    len(n.sons[a].sons[1]) == 0`  [AssertionError]

If we change the argument of the t1, t2 to both varargs[typed] or varargs[untyped], it works. Even if I change the t1 as varargs[untyped] and t2 as varargs[typed], it still works. Only varargs[untyped] call varargs[typed] doesn't work.


This comment has been minimized.

Copy link
Contributor Author

slangmgh commented Dec 22, 2018

I comment the assertion lines in the sigmatch.nim, then the code compiles and works.


This comment has been minimized.

Copy link
Contributor Author

slangmgh commented Dec 22, 2018

The code is added to fix #8715


This comment has been minimized.

Copy link

mratsim commented Jan 9, 2019

cc @narimiran @Araq backport to 0.19.4?

@Araq Araq closed this in aa7ad88 Jan 13, 2019

narimiran added a commit that referenced this issue Jan 14, 2019

fixes #10075 [backport]
(cherry picked from commit aa7ad88)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment