nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.64k stars 1.47k forks source link

Reserved keyword bind breaks importcpp pragma #8728

Open zacharycarter opened 6 years ago

zacharycarter commented 6 years ago
zachcarter@A-TX39FHTD6  ~/projects/sell-my-car-backend   master ●  nim -version
Nim Compiler Version 0.18.1 [MacOSX: amd64]
Compiled at 2018-08-22
Copyright (c) 2006-2018 by Andreas Rumpf

active boot switches: -d:release

import jsffi proc bindTo(p: proc(), self: JsObject, args: JsObject): proc() {. importcpp: "bind" .}

results in -

Error: attempting to call undeclared routine: 'importcpp

which is not very clear at all.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind#Syntax

https://nim-lang.org/docs/jsffi.html#bindMethod.m,typed - exists but users for the JS target are going to either desire a clearer error message here so they know they need to work around this with meta programming, or some type of implementation of bindMethod that also passes arguments to the closure.

Sorry if my summary of the issue was off - please edit to have it make sense.

LemonBoy commented 6 years ago

Not quite, you just have to wrap with parentheses the return type (proc()) otherwise the importcpp pragma is wrongfully attached to it rather than bindTo.

metagn commented 4 years ago

Now gives invalid pragma: importcpp: "bind". Maybe make it say invalid pragma for proc(): importcpp: "bind"?

Relevant else branch