comparison src/userfunc.c @ 33936:bdd408288d95 v9.0.2164

patch 9.0.2164: Vim9: can use type a func arg/return value Commit: https://github.com/vim/vim/commit/b077b58809f6bd1078f409829cc1964b8475f9fc Author: Ernie Rael <errael@raelity.com> Date: Thu Dec 14 20:11:44 2023 +0100 patch 9.0.2164: Vim9: can use type a func arg/return value Problem: Vim9: can use type a func arg/return value Solution: Check if using type as function argument or return value closes: #13675 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 14 Dec 2023 20:15:10 +0100
parents a49ae967e9ed
children 7c30841c60a0
comparison
equal deleted inserted replaced
33935:f4019f32b695 33936:bdd408288d95
1903 get_func_arguments( 1903 get_func_arguments(
1904 char_u **arg, 1904 char_u **arg,
1905 evalarg_T *evalarg, 1905 evalarg_T *evalarg,
1906 int partial_argc, 1906 int partial_argc,
1907 typval_T *argvars, 1907 typval_T *argvars,
1908 int *argcount) 1908 int *argcount,
1909 int is_builtin)
1909 { 1910 {
1910 char_u *argp = *arg; 1911 char_u *argp = *arg;
1911 int ret = OK; 1912 int ret = OK;
1912 int vim9script = in_vim9script(); 1913 int vim9script = in_vim9script();
1913 int evaluate = evalarg == NULL 1914 int evaluate = evalarg == NULL
1918 // skip the '(' or ',' and possibly line breaks 1919 // skip the '(' or ',' and possibly line breaks
1919 argp = skipwhite_and_linebreak(argp + 1, evalarg); 1920 argp = skipwhite_and_linebreak(argp + 1, evalarg);
1920 1921
1921 if (*argp == ')' || *argp == ',' || *argp == NUL) 1922 if (*argp == ')' || *argp == ',' || *argp == NUL)
1922 break; 1923 break;
1923 if (eval1(&argp, &argvars[*argcount], evalarg) == FAIL) 1924
1925 int arg_idx = *argcount;
1926 if (eval1(&argp, &argvars[arg_idx], evalarg) == FAIL)
1924 { 1927 {
1925 ret = FAIL; 1928 ret = FAIL;
1926 break; 1929 break;
1927 } 1930 }
1928 ++*argcount; 1931 ++*argcount;
1932 if (!is_builtin && check_typval_is_value(&argvars[arg_idx]) == FAIL)
1933 {
1934 ret = FAIL;
1935 break;
1936 }
1937
1929 // The comma should come right after the argument, but this wasn't 1938 // The comma should come right after the argument, but this wasn't
1930 // checked previously, thus only enforce it in Vim9 script. 1939 // checked previously, thus only enforce it in Vim9 script.
1931 if (vim9script) 1940 if (vim9script)
1932 { 1941 {
1933 if (*argp != ',' && *skipwhite(argp) == ',') 1942 if (*argp != ',' && *skipwhite(argp) == ',')
1983 ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE); 1992 ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE);
1984 1993
1985 argp = *arg; 1994 argp = *arg;
1986 ret = get_func_arguments(&argp, evalarg, 1995 ret = get_func_arguments(&argp, evalarg,
1987 (funcexe->fe_partial == NULL ? 0 : funcexe->fe_partial->pt_argc), 1996 (funcexe->fe_partial == NULL ? 0 : funcexe->fe_partial->pt_argc),
1988 argvars, &argcount); 1997 argvars, &argcount, builtin_function(name, -1));
1989 1998
1990 if (ret == OK) 1999 if (ret == OK)
1991 { 2000 {
1992 int i = 0; 2001 int i = 0;
1993 int did_emsg_before = did_emsg; 2002 int did_emsg_before = did_emsg;
6123 partial_argc = partial->pt_argc; 6132 partial_argc = partial->pt_argc;
6124 for (i = 0; i < partial_argc; ++i) 6133 for (i = 0; i < partial_argc; ++i)
6125 copy_tv(&partial->pt_argv[i], &argvars[i]); 6134 copy_tv(&partial->pt_argv[i], &argvars[i]);
6126 } 6135 }
6127 } 6136 }
6137 int is_builtin = builtin_function(name, -1);
6128 r = get_func_arguments(arg, evalarg, FALSE, 6138 r = get_func_arguments(arg, evalarg, FALSE,
6129 argvars + partial_argc, &argcount); 6139 argvars + partial_argc, &argcount, is_builtin);
6130 argcount += partial_argc; 6140 argcount += partial_argc;
6131 6141
6132 if (r == OK) 6142 if (r == OK)
6133 { 6143 {
6134 if (type != NULL) 6144 if (type != NULL)
6135 { 6145 {
6136 // Check that the arguments are OK for the types of the funcref. 6146 // Check that the arguments are OK for the types of the funcref.
6137 r = check_argument_types(type, argvars, argcount, NULL, name); 6147 r = check_argument_types(type, argvars, argcount, NULL, name);
6138 } 6148 }
6139 else if (builtin_function(name, -1)) 6149 else if (is_builtin)
6140 { 6150 {
6141 int idx = find_internal_func(name); 6151 int idx = find_internal_func(name);
6142 6152
6143 if (idx < 0) 6153 if (idx < 0)
6144 { 6154 {