varargs with transformation that takes var argument creates invalid c code #4545

krux02 opened this Issue Jul 30, 2016 · 0 comments


None yet

1 participant

krux02 commented Jul 30, 2016

The transformation function Converter that is passed to varargProc takes a var parameter, so a reference, and that is causing a compilation bug.


type SomeObject = objec
    a : int

type AbstractObject = object
  objet: ptr SomeObject  

proc Converter(this: var SomeObject): AbstractObject =
  AbstractObject(objet: this.addr)

proc varargProc(args : varargs[AbstractObject,Converter]): int =
  for arg in args:
    result += arg.objet.a

var obj = SomeObject(a: 17)

echo varargProc(obj)
#echo varargProc([Converter(obj)])


nim c bug
Hint: used config file '/etc/nim.cfg' [Conf]
Hint: system [Processing]
Hint: bug [Processing]
CC: bug
Error: execution of an external compiler program 'gcc -c  -w  -I/usr/lib/nim -o /home/arne/proj/nim/go-interface/nimcache/bug.o /home/arne/proj/nim/go-interface/nimcache/bug.c' failed with exit code: 256

/home/arne/proj/nim/go-interface/nimcache/bug.c: In Funktion »bugInit000«:
/home/arne/proj/nim/go-interface/nimcache/bug.c:191:39: Fehler: Inkompatibler Typ für Argument 1 von »Converter_95010_2364575462«
  LOC2[0] = Converter_95010_2364575462(obj_95062_2364575462);
In file included from /home/arne/proj/nim/go-interface/nimcache/bug.c:9:0:
/home/arne/proj/nim/go-interface/nimcache/bug.c:76:32: Anmerkung: »Someobject95004 * {aka struct Someobject95004 *}« erwartet, aber Argument hat Typ »Someobject95004 {aka struct Someobject95004}«
 N_NIMCALL(Abstractobject95007, Converter_95010_2364575462)(Someobject95004* this_95013_2364575462) {
/usr/lib/nim/nimbase.h:215:44: Anmerkung: in Definition des Makros »N_NIMCALL«
 #  define N_NIMCALL(rettype, name) rettype name /* no modifier */

The interesting thing is, that according to the documentation, the line echo varargProc(obj) is transformed to echo varargProc([Converter(obj)]). But when I actually manually do the code transformation (uncomment the last line), there is no problem at all.

@Araq Araq added a commit that closed this issue Aug 3, 2016
@Araq Araq fixes #4545 7ac0b20
@Araq Araq closed this in 7ac0b20 Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment