I have been updating my C# jsonata port to pass latest signature tests when I stumbled upon something that looks like an unexpwected behaviour to me:
|
params.forEach(function (param, index) { |
|
var arg = args[argIndex]; |
|
var match = isValid[index + 1]; |
|
if (match === '') { |
|
if (param.context && param.contextRegex) { |
|
// substitute context value for missing arg |
|
// first check that the context value is the right type |
|
var contextType = getSymbol(context); |
|
// test contextType against the regex for this arg (without the trailing ?) |
|
if (param.contextRegex.test(contextType)) { |
|
validatedArgs.push(context); |
|
} else { |
|
// context value not compatible with this argument |
|
throw { |
|
code: "T0411", |
|
stack: (new Error()).stack, |
|
value: context, |
|
index: argIndex + 1 |
|
}; |
|
} |
|
} else { |
|
validatedArgs.push(arg); |
|
argIndex++; |
|
} |
|
} else { |
specifically, if there's an empty match for a param and param is not a context/contextRegex then the function would just silently validate current arg for the param.
This seem to be plainly wrong, and it would cause stuff like this:
λ($arg1, $arg2)<s?n?:o>{{"$arg1": $arg1, "$arg2": $arg2}}(2)
produces
instead of
https://try.jsonata.org/KS7syiOV_
And
λ($arg1, $arg2)<s?n?:o>{{"$arg1": $arg1, "$arg2": $arg2}}(1,2)
produces error (expected) with unexpected message: Argument 2 of function undefined does not match function signature — one would expect that it is argument 1 that does not match the signature.
I have been updating my C# jsonata port to pass latest signature tests when I stumbled upon something that looks like an unexpwected behaviour to me:
jsonata/src/signature.js
Lines 230 to 254 in 597e5ee
specifically, if there's an empty
matchfor aparamandparamis not a context/contextRegex then the function would just silently validate currentargfor theparam.This seem to be plainly wrong, and it would cause stuff like this:
produces
{ "$arg1": 2 }instead of
{ "$arg2": 2 }https://try.jsonata.org/KS7syiOV_
And
produces error (expected) with unexpected message:
Argument 2 of function undefined does not match function signature— one would expect that it is argument 1 that does not match the signature.