Fix allowing any
to be used for optional arguments (#4659)
This commit is contained in:
parent
7588c7e31a
commit
a0028e2c7a
2 changed files with 16 additions and 0 deletions
|
@ -275,6 +275,7 @@ impl Function {
|
||||||
// Check for any final optional arguments
|
// Check for any final optional arguments
|
||||||
val.args.iter().rev().for_each(|(_, kind)| match kind {
|
val.args.iter().rev().for_each(|(_, kind)| match kind {
|
||||||
Kind::Option(_) if min_args_len == 0 => {}
|
Kind::Option(_) if min_args_len == 0 => {}
|
||||||
|
Kind::Any if min_args_len == 0 => {}
|
||||||
_ => min_args_len += 1,
|
_ => min_args_len += 1,
|
||||||
});
|
});
|
||||||
// Check the necessary arguments are passed
|
// Check the necessary arguments are passed
|
||||||
|
|
|
@ -6340,17 +6340,20 @@ pub async fn function_http_disabled() -> Result<(), Error> {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn function_custom_optional_args() -> Result<(), Error> {
|
async fn function_custom_optional_args() -> Result<(), Error> {
|
||||||
let sql = r#"
|
let sql = r#"
|
||||||
|
DEFINE FUNCTION fn::any_arg($a: any) { $a || 'test' };
|
||||||
DEFINE FUNCTION fn::zero_arg() { [] };
|
DEFINE FUNCTION fn::zero_arg() { [] };
|
||||||
DEFINE FUNCTION fn::one_arg($a: bool) { [$a] };
|
DEFINE FUNCTION fn::one_arg($a: bool) { [$a] };
|
||||||
DEFINE FUNCTION fn::last_option($a: bool, $b: option<bool>) { [$a, $b] };
|
DEFINE FUNCTION fn::last_option($a: bool, $b: option<bool>) { [$a, $b] };
|
||||||
DEFINE FUNCTION fn::middle_option($a: bool, $b: option<bool>, $c: bool) { [$a, $b, $c] };
|
DEFINE FUNCTION fn::middle_option($a: bool, $b: option<bool>, $c: bool) { [$a, $b, $c] };
|
||||||
|
|
||||||
|
RETURN fn::any_arg();
|
||||||
RETURN fn::zero_arg();
|
RETURN fn::zero_arg();
|
||||||
RETURN fn::one_arg();
|
RETURN fn::one_arg();
|
||||||
RETURN fn::last_option();
|
RETURN fn::last_option();
|
||||||
RETURN fn::middle_option();
|
RETURN fn::middle_option();
|
||||||
|
|
||||||
RETURN fn::zero_arg(true);
|
RETURN fn::zero_arg(true);
|
||||||
|
RETURN fn::any_arg('other');
|
||||||
RETURN fn::one_arg(true);
|
RETURN fn::one_arg(true);
|
||||||
RETURN fn::last_option(true);
|
RETURN fn::last_option(true);
|
||||||
RETURN fn::last_option(true, false);
|
RETURN fn::last_option(true, false);
|
||||||
|
@ -6376,6 +6379,14 @@ async fn function_custom_optional_args() -> Result<(), Error> {
|
||||||
assert_eq!(tmp, val);
|
assert_eq!(tmp, val);
|
||||||
//
|
//
|
||||||
let tmp = test.next()?.result?;
|
let tmp = test.next()?.result?;
|
||||||
|
let val = Value::None;
|
||||||
|
assert_eq!(tmp, val);
|
||||||
|
//
|
||||||
|
let tmp = test.next()?.result?;
|
||||||
|
let val = Value::parse("'test'");
|
||||||
|
assert_eq!(tmp, val);
|
||||||
|
//
|
||||||
|
let tmp = test.next()?.result?;
|
||||||
let val = Value::parse("[]");
|
let val = Value::parse("[]");
|
||||||
assert_eq!(tmp, val);
|
assert_eq!(tmp, val);
|
||||||
//
|
//
|
||||||
|
@ -6416,6 +6427,10 @@ async fn function_custom_optional_args() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
let tmp = test.next()?.result?;
|
let tmp = test.next()?.result?;
|
||||||
|
let val = Value::parse("'other'");
|
||||||
|
assert_eq!(tmp, val);
|
||||||
|
//
|
||||||
|
let tmp = test.next()?.result?;
|
||||||
let val = Value::parse("[true]");
|
let val = Value::parse("[true]");
|
||||||
assert_eq!(tmp, val);
|
assert_eq!(tmp, val);
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue