-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Argument names for functions should be mangled when using value-argument syntax #2039
Comments
I think I must have sensed this would be a problem when I added that... This isn't quite a bug because the docs should make it obvious to the user, however, it is easy to be surprised by this. This should be trivial to fix in However, by now there may exist code that depends on this behavior, so I think perhaps it's too late to change this. Let's sleep on it. |
Perhaps we should add a warning to the documentation about this. |
A warning pointing out this scenario would be helpful. Perhaps in a future future version, consider have a "fix" as a breaking change. When using this syntax, one shouldn't expect the value-param I took a shot at the fix in JeffreyMercado:mangle-params |
I actually think that mangling is a really nice approach. |
I don't like mangling. Either bind the non- |
Describe the bug
When you define a function but want value semantics for arguments, you could use the shorthand:
which is equivalent to:
https://stedolan.github.io/jq/manual/#DefiningFunctions
This poses a problem if the value-argument name happens to share the name of a function that's in scope, the local argument is used. Can be confusing (see repro).
Instead, some sort of name mangling should be performed so it's equivalent to something along the lines of:
To Reproduce
workaround, change arg name:
Expected behavior
The argument name should not conflict with names in scope when value-argument shorthand is used. Slight semantic change but I'd argue it's less confusing.
Environment (please complete the following information):
jq <=1.6
Additional context
Was defining some helper functions and wanted to create string padding functions and started with this initially.
Fix using the name
$size
instead of$length
.The text was updated successfully, but these errors were encountered: