Patch 8.2.1285
Problem: Vim9: argument types are not checked on assignment.
Solution: Check function argument types. (issue #6507)
Files: src/vim9compile.c, src/testdir/test_vim9_func.vim
*** ../vim-8.2.1284/src/vim9compile.c 2020-07-23 20:09:06.712083716 +0200
--- src/vim9compile.c 2020-07-23 20:54:31.235894117 +0200
***************
*** 638,643 ****
--- 638,655 ----
&& (actual->tt_argcount < expected->tt_min_argcount
|| actual->tt_argcount > expected->tt_argcount))
ret = FAIL;
+ if (expected->tt_args != NULL && actual->tt_args != NULL)
+ {
+ int i;
+
+ for (i = 0; i < expected->tt_argcount; ++i)
+ if (check_type(expected->tt_args[i], actual->tt_args[i],
+ FALSE) == FAIL)
+ {
+ ret = FAIL;
+ break;
+ }
+ }
}
if (ret == FAIL && give_msg)
type_mismatch(expected, actual);
***************
*** 2819,2824 ****
--- 2831,2840 ----
if (ufunc == NULL)
return FAIL;
+ // Need to compile any default values to get the argument types.
+ if (ufunc->uf_def_status == UF_TO_BE_COMPILED)
+ if (compile_def_function(ufunc, TRUE, NULL) == FAIL)
+ return FAIL;
return generate_PUSHFUNC(cctx, vim_strsave(ufunc->uf_name),
ufunc->uf_func_type);
}
***************
*** 6995,7000 ****
--- 7011,7017 ----
int i;
char_u *arg;
int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0);
+ int did_set_arg_type = FALSE;
// Produce instructions for the default values of optional arguments.
// Store the instruction index in uf_def_arg_idx[] so that we know
***************
*** 7019,7025 ****
--- 7036,7045 ----
// specified type.
val_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
if (ufunc->uf_arg_types[arg_idx] == &t_unknown)
+ {
+ did_set_arg_type = TRUE;
ufunc->uf_arg_types[arg_idx] = val_type;
+ }
else if (check_type(ufunc->uf_arg_types[arg_idx], val_type, FALSE)
== FAIL)
{
***************
*** 7032,7037 ****
--- 7052,7060 ----
goto erret;
}
ufunc->uf_def_arg_idx[count] = instr->ga_len;
+
+ if (did_set_arg_type)
+ set_function_type(ufunc);
}
/*
*** ../vim-8.2.1284/src/testdir/test_vim9_func.vim 2020-07-23
20:09:06.712083716 +0200
--- src/testdir/test_vim9_func.vim 2020-07-23 20:33:10.665710893 +0200
***************
*** 293,298 ****
--- 293,307 ----
Funcref(123)
END
CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ def UseNumber(nr: number)
+ echo nr
+ enddef
+ let Funcref: func(string) = function('UseNumber')
+ END
+ CheckScriptFailure(lines, 'E1013: type mismatch, expected func(string) but
got func(number)')
enddef
let SomeFunc = function('len')
*** ../vim-8.2.1284/src/version.c 2020-07-23 20:09:06.712083716 +0200
--- src/version.c 2020-07-23 20:30:10.674442450 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1285,
/**/
--
hundred-and-one symptoms of being an internet addict:
75. You start wondering whether you could actually upgrade your brain
with a Pentium Pro microprocessor 80. The upgrade works just fine.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202007231857.06NIvJ2Y149763%40masaka.moolenaar.net.