Nim icon indicating copy to clipboard operation
Nim copied to clipboard

`macros.error`, `macros.warning`, `macros.hint` easily conflict with routines with the same name

Open metagn opened this issue 1 year ago • 0 comments
trafficstars

Originally encountered with an error here.

The routines named error, warning and hint in macros all take a single string argument and an optional NimNode argument for the line info, and return void. This means that calls like error("abc") will match the overload in macros.

But this is a feasible signature for procs in user code, especially logging libraries (like chronicles, which happens to work around it by requiring the string also be static). If macros is imported, calling these procs can easily give overload ambiguity errors. But the macros overloads are more specialized, they are only for compile time errors in macros.

To fix this, we can rename the overloads in macros to something like macroError, compileTimeError etc. (not sure which name is best, would appreciate suggestions), then deprecate the old symbols/remove them with a define. Alternatively we can also require the NimNode argument for the line info be provided explicitly, but this could still conflict with procs that accept values of any type and stringify them.

metagn avatar Oct 07 '24 03:10 metagn