Can anyone please help me find out what's wrong with this code?
Thanks in advance for any help!
import macros
macro thirteen(args: varargs[expr]): expr =
  result = newIntLitNode(13)
assert(13==thirteen([1,2,3,4])) # works
assert(13==thirteen(1,2,3,4)) # works
assert(13==thirteen(1,2,[3,4])) # does not work
assert(13==thirteen([1,2,3], 4)) # does not work
# compilation error is:
#
# type_mismatch_test.nim(9, 19) Error: type mismatch: got (int literal(1), int literal(2), Array constructor[0..1, int])
# but expected one of:
# type_mismatch_test.thirteen(args: varargs[expr]): expr
#
# obtained with Nimrod devel, rev. a600ce527ccdf0
Isn't the problem that you are mixing types? All the parameters have to be of the same time. You get a similar compiler error when you try to declare a mixed sequence:
when isMainModule:
  var x = @[1, 2, [3, 4]]
private/tmp/n/mi.nim(3, 18) Error: type mismatch: got (Array constructor[0..1, int]) but expected 'int literal(1)'
All the arguments have the "expr" type.
BTW, Araq confirmed that this is a bug on irc, and I've filed a bug report:
https://github.com/Araq/Nimrod/issues/913
Cheers.