@ in importcpp should work with no-argument functions #4496

Closed
mcclure opened this Issue Jul 18, 2016 · 1 comment

Projects

None yet

2 participants

@mcclure
mcclure commented Jul 18, 2016

The exact semantics of @ and # are not explained in the manual, but. Here's a small test program:

proc one(x:float) : void {.importcpp:"one(@)".}
proc two() : void {.importcpp:"two(@)".}
proc three(x:float = 3) : void {.importcpp:"thr(@)".}

one(2)
two()
three(4)
three()

My expected behavior is that the @ should be interpreted identically with all four of these invocations. However when I run nim js -o:example.js example.nim on this code, the final four lines are:

one(2.0000000000000000e+000);
two(@)();
three(4.0000000000000000e+000);
three(3.0000000000000000e+000);

So the @ is not interpreted in the case of the proc with no arguments. This is a minor thing but in my opinion it should not work this way, it is inconsistent and it creates an irritation when generating binding scripts (I am doing this, and I have to special-case zero-argument functions and use a different importc statement). Instead @ should interpolate the argument list for two() [in this case an empty string]

@mbaulch
Contributor
mbaulch commented Jul 18, 2016

It seems to work with the cpp (C++) backend. An extract of the output:

   nimln(5, "importcpp_noarg.nim");
   one(2.0000000000000000e+00);
   nimln(6, "importcpp_noarg.nim");
   two();
   nimln(7, "importcpp_noarg.nim");
   thr(4.0000000000000000e+00);
   nimln(8, "importcpp_noarg.nim");
   thr(3.0000000000000000e+00);

I don't believe the importcpp pragma is intended for use in the js backend. From the manual:

the importcpp pragma can be used to import C++ methods or C++ symbols in general

Perhaps the compiler should report an error when the importcpp pragma is used unless with the cpp backend?

@Araq Araq added a commit that closed this issue Jul 18, 2016
@Araq Araq fixes #4496 f1e77d3
@Araq Araq closed this in f1e77d3 Jul 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment